📄 rs_entitycontainer.cpp
字号:
/** * Recalculates the borders of this entity container including * invisible entities. */void RS_EntityContainer::forcedCalculateBorders() { //RS_DEBUG->print("RS_EntityContainer::calculateBorders"); resetBorders(); for (RS_Entity* e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone)) { //RS_Layer* layer = e->getLayer(); if (e->isContainer()) { ((RS_EntityContainer*)e)->forcedCalculateBorders(); } else { e->calculateBorders(); } adjustBorders(e); } // needed for correcting corrupt data (PLANS.dxf) if (minV.x>maxV.x || minV.x>RS_MAXDOUBLE || maxV.x>RS_MAXDOUBLE || minV.x<RS_MINDOUBLE || maxV.x<RS_MINDOUBLE) { minV.x = 0.0; maxV.x = 0.0; } if (minV.y>maxV.y || minV.y>RS_MAXDOUBLE || maxV.y>RS_MAXDOUBLE || minV.y<RS_MINDOUBLE || maxV.y<RS_MINDOUBLE) { minV.y = 0.0; maxV.y = 0.0; } //RS_DEBUG->print(" borders: %f/%f %f/%f", minV.x, minV.y, maxV.x, maxV.y); //printf("borders: %lf/%lf %lf/%lf\n", minV.x, minV.y, maxV.x, maxV.y); //RS_Entity::calculateBorders();}/** * Updates all Dimension entities in this container and * reposition their labels. */void RS_EntityContainer::updateDimensions() { RS_DEBUG->print("RS_EntityContainer::updateDimensions()"); //for (RS_Entity* e=firstEntity(RS2::ResolveNone); // e!=NULL; // e=nextEntity(RS2::ResolveNone)) { RS_PtrListIterator<RS_Entity> it = createIterator(); RS_Entity* e; while ( (e = it.current()) != NULL ) { ++it; if (RS_Information::isDimension(e->rtti())) { // update and reposition label: ((RS_Dimension*)e)->update(true); } else if (e->isContainer()) { ((RS_EntityContainer*)e)->updateDimensions(); } } RS_DEBUG->print("RS_EntityContainer::updateDimensions() OK");}/** * Updates all Insert entities in this container. */void RS_EntityContainer::updateInserts() { RS_DEBUG->print("RS_EntityContainer::updateInserts()"); //for (RS_Entity* e=firstEntity(RS2::ResolveNone); // e!=NULL; // e=nextEntity(RS2::ResolveNone)) { RS_PtrListIterator<RS_Entity> it = createIterator(); RS_Entity* e; while ( (e = it.current()) != NULL ) { ++it; //// Only update our own inserts and not inserts of inserts if (e->rtti()==RS2::EntityInsert /*&& e->getParent()==this*/) { ((RS_Insert*)e)->update(); } else if (e->isContainer() && e->rtti()!=RS2::EntityHatch) { ((RS_EntityContainer*)e)->updateInserts(); } } RS_DEBUG->print("RS_EntityContainer::updateInserts() OK");}/** * Renames all inserts with name 'oldName' to 'newName'. This is * called after a block was rename to update the inserts. */void RS_EntityContainer::renameInserts(const RS_String& oldName, const RS_String& newName) { RS_DEBUG->print("RS_EntityContainer::renameInserts()"); //for (RS_Entity* e=firstEntity(RS2::ResolveNone); // e!=NULL; // e=nextEntity(RS2::ResolveNone)) { RS_PtrListIterator<RS_Entity> it = createIterator(); RS_Entity* e; while ( (e = it.current()) != NULL ) { ++it; if (e->rtti()==RS2::EntityInsert) { RS_Insert* i = ((RS_Insert*)e); if (i->getName()==oldName) { i->setName(newName); } } else if (e->isContainer()) { ((RS_EntityContainer*)e)->renameInserts(oldName, newName); } } RS_DEBUG->print("RS_EntityContainer::renameInserts() OK");}/** * Updates all Spline entities in this container. */void RS_EntityContainer::updateSplines() { RS_DEBUG->print("RS_EntityContainer::updateSplines()"); //for (RS_Entity* e=firstEntity(RS2::ResolveNone); // e!=NULL; // e=nextEntity(RS2::ResolveNone)) { RS_PtrListIterator<RS_Entity> it = createIterator(); RS_Entity* e; while ( (e = it.current()) != NULL ) { ++it; //// Only update our own inserts and not inserts of inserts if (e->rtti()==RS2::EntitySpline /*&& e->getParent()==this*/) { ((RS_Spline*)e)->update(); } else if (e->isContainer() && e->rtti()!=RS2::EntityHatch) { ((RS_EntityContainer*)e)->updateSplines(); } } RS_DEBUG->print("RS_EntityContainer::updateSplines() OK");}/** * Updates the sub entities of this container. */void RS_EntityContainer::update() { //for (RS_Entity* e=firstEntity(RS2::ResolveNone); // e!=NULL; // e=nextEntity(RS2::ResolveNone)) { RS_PtrListIterator<RS_Entity> it = createIterator(); RS_Entity* e; while ( (e = it.current()) != NULL ) { ++it; e->update(); }}/** * Returns the first entity or NULL if this graphic is empty. * @param level */RS_Entity* RS_EntityContainer::firstEntity(RS2::ResolveLevel level) { switch (level) { case RS2::ResolveNone: return entities.first(); break; case RS2::ResolveAllButInserts: { subContainer=NULL; RS_Entity* e = entities.first(); if (e!=NULL && e->isContainer() && e->rtti()!=RS2::EntityInsert) { subContainer = (RS_EntityContainer*)e; e = ((RS_EntityContainer*)e)->firstEntity(level); // emtpy container: if (e==NULL) { subContainer = NULL; e = nextEntity(level); } } return e; } break; case RS2::ResolveAll: { subContainer=NULL; RS_Entity* e = entities.first(); if (e!=NULL && e->isContainer()) { subContainer = (RS_EntityContainer*)e; e = ((RS_EntityContainer*)e)->firstEntity(level); // emtpy container: if (e==NULL) { subContainer = NULL; e = nextEntity(level); } } return e; } break; } return NULL;}/** * Returns the last entity or \p NULL if this graphic is empty. * * @param level \li \p 0 Groups are not resolved * \li \p 1 (default) only Groups are resolved * \li \p 2 all Entity Containers are resolved */RS_Entity* RS_EntityContainer::lastEntity(RS2::ResolveLevel level) { switch (level) { case RS2::ResolveNone: return entities.last(); break; case RS2::ResolveAllButInserts: { RS_Entity* e = entities.last(); subContainer = NULL; if (e!=NULL && e->isContainer() && e->rtti()!=RS2::EntityInsert) { subContainer = (RS_EntityContainer*)e; e = ((RS_EntityContainer*)e)->lastEntity(level); } return e; } break; case RS2::ResolveAll: { RS_Entity* e = entities.last(); subContainer = NULL; if (e!=NULL && e->isContainer()) { subContainer = (RS_EntityContainer*)e; e = ((RS_EntityContainer*)e)->lastEntity(level); } return e; } break; } return NULL;}/** * Returns the next entity or container or \p NULL if the last entity * returned by \p next() was the last entity in the container. */RS_Entity* RS_EntityContainer::nextEntity(RS2::ResolveLevel level) { switch (level) { case RS2::ResolveNone: return entities.next(); break; case RS2::ResolveAllButInserts: { RS_Entity* e=NULL; if (subContainer!=NULL) { e = subContainer->nextEntity(level); if (e!=NULL) { return e; } else { e = entities.next(); } } else { e = entities.next(); } if (e!=NULL && e->isContainer() && e->rtti()!=RS2::EntityInsert) { subContainer = (RS_EntityContainer*)e; e = ((RS_EntityContainer*)e)->firstEntity(level); // emtpy container: if (e==NULL) { subContainer = NULL; e = nextEntity(level); } } return e; } break; case RS2::ResolveAll: { RS_Entity* e=NULL; if (subContainer!=NULL) { e = subContainer->nextEntity(level); if (e!=NULL) { return e; } else { e = entities.next(); } } else { e = entities.next(); } if (e!=NULL && e->isContainer()) { subContainer = (RS_EntityContainer*)e; e = ((RS_EntityContainer*)e)->firstEntity(level); // emtpy container: if (e==NULL) { subContainer = NULL; e = nextEntity(level); } } return e; } break; } return NULL;}/** * Returns the prev entity or container or \p NULL if the last entity * returned by \p prev() was the first entity in the container. */RS_Entity* RS_EntityContainer::prevEntity(RS2::ResolveLevel level) { switch (level) { case RS2::ResolveNone: return entities.prev(); break; case RS2::ResolveAllButInserts: { RS_Entity* e=NULL; if (subContainer!=NULL) { e = subContainer->prevEntity(level); if (e!=NULL) { return e; } else { e = entities.prev(); } } else { e = entities.prev(); } if (e!=NULL && e->isContainer() && e->rtti()!=RS2::EntityInsert) { subContainer = (RS_EntityContainer*)e; e = ((RS_EntityContainer*)e)->lastEntity(level); // emtpy container: if (e==NULL) { subContainer = NULL; e = prevEntity(level); } } return e; } case RS2::ResolveAll: { RS_Entity* e=NULL; if (subContainer!=NULL) { e = subContainer->prevEntity(level); if (e!=NULL) { return e; } else { e = entities.prev(); } } else { e = entities.prev(); } if (e!=NULL && e->isContainer()) { subContainer = (RS_EntityContainer*)e; e = ((RS_EntityContainer*)e)->lastEntity(level); // emtpy container: if (e==NULL) { subContainer = NULL; e = prevEntity(level); } } return e; } } return NULL;}/** * @return Entity at the given index or NULL if the index is out of range. */RS_Entity* RS_EntityContainer::entityAt(uint index) { return entities.at(index);}/** * @return Current index. */int RS_EntityContainer::entityAt() { return entities.at();}/** * Finds the given entity and makes it the current entity if found. */int RS_EntityContainer::findEntity(RS_Entity* entity) { return entities.find(entity);}/** * @return The current entity. */RS_Entity* RS_EntityContainer::currentEntity() { return entities.current();}/** * Returns the copy to a new iterator for traversing the entities. */RS_PtrListIterator<RS_Entity> RS_EntityContainer::createIterator() { return RS_PtrListIterator<RS_Entity>(entities);}/** * @return The point which is closest to 'coord' * (one of the vertexes) */RS_Vector RS_EntityContainer::getNearestEndpoint(const RS_Vector& coord, double* dist) { double minDist = RS_MAXDOUBLE; // minimum measured distance double curDist; // currently measured distance RS_Vector closestPoint(false); // closest found endpoint RS_Vector point; // endpoint found //RS_PtrListIterator<RS_Entity> it = createIterator(); //RS_Entity* en; //while ( (en = it.current()) != NULL ) { // ++it; for (RS_Entity* en = firstEntity(); en != NULL; en = nextEntity()) { if (en->isVisible()) { point = en->getNearestEndpoint(coord, &curDist); if (point.valid && curDist<minDist) { closestPoint = point; minDist = curDist; if (dist!=NULL) { *dist = curDist; } } } } return closestPoint;}RS_Vector RS_EntityContainer::getNearestPointOnEntity(const RS_Vector& coord, bool onEntity, double* dist, RS_Entity** entity) { RS_Vector point(false); RS_Entity* e = getNearestEntity(coord, dist, RS2::ResolveNone); if (e!=NULL && e->isVisible()) { point = e->getNearestPointOnEntity(coord, onEntity, dist, entity); } return point;}RS_Vector RS_EntityContainer::getNearestCenter(const RS_Vector& coord, double* dist) { RS_Vector point(false); RS_Entity* closestEntity; //closestEntity = getNearestEntity(coord, NULL, RS2::ResolveAll); closestEntity = getNearestEntity(coord, NULL, RS2::ResolveNone); if (closestEntity!=NULL) { point = closestEntity->getNearestCenter(coord, dist); } return point;}RS_Vector RS_EntityContainer::getNearestMiddle(const RS_Vector& coord, double* dist) { RS_Vector point(false); RS_Entity* closestEntity; closestEntity = getNearestEntity(coord, NULL, RS2::ResolveNone); if (closestEntity!=NULL) { point = closestEntity->getNearestMiddle(coord, dist); } return point; /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -