/** * Catches an entity which is close to the given position 'pos'. * * @param pos A graphic coordinate. * @param level The level of resolving for iterating through the entity * container * @enType, only search for a particular entity type * @return Pointer to the entity or nullptr. */ RS_Entity* RS_Snapper::catchEntity(const RS_Vector& pos, RS2::EntityType enType, RS2::ResolveLevel level) { RS_DEBUG->print("RS_Snapper::catchEntity"); // std::cout<<"RS_Snapper::catchEntity(): enType= "<<enType<<std::endl; // set default distance for points inside solids RS_EntityContainer ec(nullptr,false); //isContainer bool isContainer{false}; switch(enType){ case RS2::EntityPolyline: case RS2::EntityContainer: case RS2::EntitySpline: isContainer=true; break; default: break; } for(RS_Entity* en= container->firstEntity(level);en;en=container->nextEntity(level)){ if(en->isVisible()==false) continue; if(en->rtti() != enType && isContainer){ //whether this entity is a member of member of the type enType RS_Entity* parent(en->getParent()); bool matchFound{false}; while(parent ) { // std::cout<<"RS_Snapper::catchEntity(): parent->rtti()="<<parent->rtti()<<" enType= "<<enType<<std::endl; if(parent->rtti() == enType) { matchFound=true; ec.addEntity(en); break; } parent=parent->getParent(); } if(!matchFound) continue; } if (en->rtti() == enType){ ec.addEntity(en); } } if (ec.count() == 0 ) return nullptr; double dist(0.); RS_Entity* entity = ec.getNearestEntity(pos, &dist, RS2::ResolveNone); int idx = -1; if (entity && entity->getParent()) { idx = entity->getParent()->findEntity(entity); } if (entity && dist<=getSnapRange()) { // highlight: RS_DEBUG->print("RS_Snapper::catchEntity: found: %d", idx); return entity; } else { RS_DEBUG->print("RS_Snapper::catchEntity: not found"); return nullptr; } }
/** * Catches an entity which is close to the given position 'pos'. * * @param pos A graphic coordinate. * @param level The level of resolving for iterating through the entity * container * @return Pointer to the entity or NULL. */ RS_Entity* RS_Snapper::catchEntity(const RS_Vector& pos, RS2::ResolveLevel level) { RS_DEBUG->print("RS_Snapper::catchEntity"); // set default distance for points inside solids double dist (0.); // std::cout<<"getSnapRange()="<<getSnapRange()<<"\tsnap distance = "<<dist<<std::endl; RS_Entity* entity = container->getNearestEntity(pos, &dist, level); int idx = -1; if (entity!=NULL && entity->getParent()!=NULL) { idx = entity->getParent()->findEntity(entity); } if (entity!=NULL && dist<=getSnapRange()) { // highlight: RS_DEBUG->print("RS_Snapper::catchEntity: found: %d", idx); return entity; } else { RS_DEBUG->print("RS_Snapper::catchEntity: not found"); return NULL; } RS_DEBUG->print("RS_Snapper::catchEntity: OK"); }
/** * Initialize (called by all constructors) */ void RS_Snapper::init() { snapMode = graphicView->getDefaultSnapMode(); keyEntity = nullptr; pImpData->snapSpot = RS_Vector{false}; pImpData->snapCoord = RS_Vector{false}; m_SnapDistance = 1.0; RS_SETTINGS->beginGroup("/Appearance"); snap_indicator->lines_state = RS_SETTINGS->readNumEntry("/indicator_lines_state", 1); snap_indicator->lines_type = RS_SETTINGS->readEntry("/indicator_lines_type", "Crosshair"); snap_indicator->shape_state = RS_SETTINGS->readNumEntry("/indicator_shape_state", 1); snap_indicator->shape_type = RS_SETTINGS->readEntry("/indicator_shape_type", "Circle"); RS_SETTINGS->endGroup(); RS_SETTINGS->beginGroup("Colors"); QString snap_color = RS_SETTINGS->readEntry("/snap_indicator", Colors::snap_indicator); RS_SETTINGS->endGroup(); snap_indicator->lines_pen = RS_Pen(RS_Color(snap_color), RS2::Width00, RS2::DashLine2); snap_indicator->shape_pen = RS_Pen(RS_Color(snap_color), RS2::Width00, RS2::SolidLine); snap_indicator->shape_pen.setScreenWidth(1); snapRange=getSnapRange(); }
/** * Initialize (called by all constructors) */ void RS_Snapper::init() { snapMode = graphicView->getDefaultSnapMode(); //snapRes = graphicView->getSnapRestriction(); keyEntity = NULL; snapSpot = RS_Vector(false); snapCoord = RS_Vector(false); distance = 1.0; // RS_SETTINGS->beginGroup("/Snap"); // snapRange = RS_SETTINGS->readNumEntry("/Range", 20); // //middlePoints behaviors weird, add brutal force here // //todo, clean up middlePoints // //middlePoints= RS_SETTINGS->readNumEntry("/MiddlePoints", 1); // //distance=RS_SETTINGS->readEntry("/Distance", QString("1")).toDouble(); // RS_SETTINGS->endGroup(); RS_SETTINGS->beginGroup("/Appearance"); showCrosshairs = (bool)RS_SETTINGS->readNumEntry("/ShowCrosshairs", 1); RS_SETTINGS->endGroup(); snapRange=getSnapRange(); }