how can judge a block entity

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
liguosheng
Active Member
Posts: 33
Joined: Thu Jan 14, 2016 4:17 am

how can judge a block entity

Post by liguosheng » Mon Mar 21, 2016 9:27 am

I can get entity by the following code :
REntity::Id entityId = di->getClosestEntity(e);
QSharedPointer<REntity> entity = doc->queryEntity(entityId);

then the entity is highlighted.
But, if it is a part of a block, it can't.

Then, the entity is judged firstly, the code is:
RS::EntityType type = entity->getType();

if(type == RS::EntityBlockRef)
return true;
else
return false;

it can't also. How can do?
thanks. :?

liguosheng
Active Member
Posts: 33
Joined: Thu Jan 14, 2016 4:17 am

Re: how can judge a block entity

Post by liguosheng » Mon Mar 21, 2016 9:57 am

When i debug program step by step, i found the value of variable entityId was -1, that's ,the following code isn't make:
REntity::Id entityId = di->getClosestEntity(e);

How can get block entity on earth? :cry:

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: how can judge a block entity

Post by andrew » Mon Mar 21, 2016 10:00 am

liguosheng wrote:REntity::Id entityId = di->getClosestEntity(e);
What is 'e'?

liguosheng
Active Member
Posts: 33
Joined: Thu Jan 14, 2016 4:17 am

Re: how can judge a block entity

Post by liguosheng » Mon Mar 21, 2016 10:04 am

e is parameter of a function, it's type is RMouseEvent, which is passed by mouseMoveEvent function.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: how can judge a block entity

Post by andrew » Mon Mar 21, 2016 10:20 am

OK.

RDocumentInterface::getClosestEntity returns the entity closest to the mouse cursor if there is an entity within range of the mouse cursor. -1 is returned if no entity is within range. The mouse cursor range in pixels is configured in QCAD3.ini under GraphicsView > PickRange and defaults to 10 pixels.

For more control, you can use the other RDocumentInterface::getClosestEntity instead:
/**
 * \return Entity closest to the given position within the given range.
 *
 * \param range Maximum range in drawing units.
 * \param strictRange Maximum range from either end point of the entity.
 *   Zero to only return distances that are strictly orthogonal to the entity.
 * \param includeLockedLayers Return entities on locked layers.
 * \param selectedOnly Only return selected entities.
 */
REntity::Id RDocumentInterface::getClosestEntity(const RVector& position, double range, double strictRange, bool includeLockedLayers, bool selectedOnly);

liguosheng
Active Member
Posts: 33
Joined: Thu Jan 14, 2016 4:17 am

Re: how can judge a block entity

Post by liguosheng » Mon Mar 21, 2016 10:44 am

if an entity isn't a block, it's ok, the entity can be selected. the return value isn't -1.
when i create a block, i cann't select it by mouseMoveEvent or mousePressEvent.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: how can judge a block entity

Post by andrew » Mon Mar 21, 2016 10:53 am

Is the entity you are trying to retrieve a block reference or a line, arc, circle, etc. that is part of a block definition?

Note that a block definition is not an entity but an instance of 'RBlock'. A block reference (RBlockReferenceEntity) is an entity which is used to insert a block at a given position, at a given angle, scale, etc.

liguosheng
Active Member
Posts: 33
Joined: Thu Jan 14, 2016 4:17 am

Re: how can judge a block entity

Post by liguosheng » Mon Mar 21, 2016 11:05 am

the value -1 is returned when cursor is over the line of a body by getClosestEntity, if the entity isn't a part of a block, the value is normal by getClosestEntity.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: how can judge a block entity

Post by andrew » Mon Mar 21, 2016 11:17 am

There could be various reasons for this:
- you are trying to get the ID of the closest block reference but you did not create any block references from the block (i.e. there is a block definition but it is not used at all).
- you are trying to get the entity inside the block definition but the block is not the current (active) block (see RDocumentInterface::setCurrentBlock()).

Perhaps, you can provide screenshots, DXF files, etc. to help me understand what you are trying to do.

liguosheng
Active Member
Posts: 33
Joined: Thu Jan 14, 2016 4:17 am

Re: how can judge a block entity

Post by liguosheng » Mon Mar 21, 2016 11:46 am

Block and RBlockReferenceEntity are created by selection,when i set current block by the following code:
di->setCurrentBlock(strName);
only entities belong to block are showed on view.

my meaning is:i want to select a block by selecing a entity if it's a part of block.
That is it: edit block from reference.

liguosheng
Active Member
Posts: 33
Joined: Thu Jan 14, 2016 4:17 am

Re: how can judge a block entity

Post by liguosheng » Mon Mar 21, 2016 12:01 pm

on qcad3, after the file is opened, when i select 'edit block from reference', the block cann't be selected.
Attachments
20160321.dxf
(21.84 KiB) Downloaded 479 times

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: how can judge a block entity

Post by andrew » Mon Mar 21, 2016 1:05 pm

liguosheng wrote:on qcad3, after the file is opened, when i select 'edit block from reference', the block cann't be selected.
I cannot find any problems with this file.

I proceed as follows:
1. Load the file
2. Block > Edit Block from Reference
3. Click one of the lines which are part of the block reference
4. The block definition of block "block 1" is now shown. The block definition consists of the entities that make up (or "define") that block.
5. You can now edit the block definition by adding, modifying or deleting entities.
6. When you are done, choose Block > Return to Main Drawing. This will display the main drawing (block "*Model_Space") again.

User avatar
J-J
Moderator
Posts: 502
Joined: Tue Mar 24, 2009 9:48 pm

Re: how can judge a block entity

Post by J-J » Tue Mar 22, 2016 9:28 am

I was curious, I tried the file posted by liguosheng and I find similar results:

When the cursor hovers on the block, there is no change in the color to indicate that an entity is there. The only way to select the block is with a mouse swipe, either to the left or to the right... e_confused
JJ Win7 pro-64

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: how can judge a block entity

Post by andrew » Tue Mar 22, 2016 9:36 am

J-J, liguosheng: what QCAD versions are you using? This is likely related to:
http://www.qcad.org/bugtracker/index.ph ... sk_id=1395
This issue was fixed in QCAD 3.13.

User avatar
J-J
Moderator
Posts: 502
Joined: Tue Mar 24, 2009 9:48 pm

Re: how can judge a block entity

Post by J-J » Tue Mar 22, 2016 10:01 am

Sorry Andrew, still on 3.12.8, trying to catch up from a business trip.
JJ Win7 pro-64

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”