📄 rs_modification.cpp
字号:
if (e->isAtomic()) { RS_AtomicEntity* ae = (RS_AtomicEntity*)e; double bulge = 0.0; if (ae->rtti()==RS2::EntityArc) { RS_DEBUG->print("RS_Modification::deletePolylineNode: arc segment"); bulge = ((RS_Arc*)ae)->getBulge(); } else { RS_DEBUG->print("RS_Modification::deletePolylineNode: line segment"); bulge = 0.0; } // last entity is closing entity and will be added below with endPolyline() if (e==lastEntity && polyline.isClosed()) { continue; } // first vertex (startpoint) if (first && node.distanceTo(ae->getStartpoint())>1.0e-6) { RS_DEBUG->print("RS_Modification::deletePolylineNode: first node: %f/%f", ae->getStartpoint().x, ae->getStartpoint().y); newPolyline->setNextBulge(bulge); newPolyline->addVertex(ae->getStartpoint()); first = false; } // normal node (not deleted): if (first==false && node.distanceTo(ae->getEndpoint())>1.0e-6) { RS_DEBUG->print("RS_Modification::deletePolylineNode: normal vertex found: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); if (lastDropped) { //bulge = 0.0; } newPolyline->setNextBulge(bulge); newPolyline->addVertex(ae->getEndpoint()); lastDropped = false; } // drop deleted node: else { RS_DEBUG->print("RS_Modification::deletePolylineNode: deleting vertex: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); lastDropped = true; } } else { RS_DEBUG->print("RS_Modification::deletePolylineNode: " "Polyline contains non-atomic entities", RS_Debug::D_WARNING); } } RS_DEBUG->print("RS_Modification::deletePolylineNode: ending polyline"); newPolyline->setNextBulge(polyline.getClosingBulge()); newPolyline->endPolyline(); //if (newPolyline->count()==1) { //} // add new polyline: RS_DEBUG->print("RS_Modification::deletePolylineNode: adding new polyline"); container->addEntity(newPolyline); if (graphicView!=NULL) { graphicView->deleteEntity(&polyline); graphicView->drawEntity(newPolyline); } RS_DEBUG->print("RS_Modification::deletePolylineNode: handling undo"); if (document!=NULL && handleUndo) { document->startUndoCycle(); polyline.setUndoState(true); document->addUndoable(&polyline); document->addUndoable(newPolyline); document->endUndoCycle(); } return newPolyline;}*//** * Deletes all nodes between the two given nodes (exclusive). * * @param node1 First limiting node. * @param node2 Second limiting node. * * @return Pointer to the new polyline or NULL. *//*RS_Polyline* RS_Modification::deletePolylineNodesBetween(RS_Polyline& polyline, RS_AtomicEntity& segment, const RS_Vector& node1, const RS_Vector& node2) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween"); if (container==NULL) { RS_DEBUG->print("RS_Modification::addPolylineNodesBetween: no valid container", RS_Debug::D_WARNING); return NULL; } if (node1.valid==false || node2.valid==false) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "node not valid", RS_Debug::D_WARNING); return NULL; } if (node1.distanceTo(node2)<1.0e-6) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "nodes are identical", RS_Debug::D_WARNING); return NULL; } // check if there's nothing to delete: for (RS_Entity* e=polyline.firstEntity(); e!=NULL; e=polyline.nextEntity()) { if (e->isAtomic()) { RS_AtomicEntity* ae = (RS_AtomicEntity*)e; if ((node1.distanceTo(ae->getStartpoint())<1.0e-6 && node2.distanceTo(ae->getEndpoint())<1.0e-6) || (node2.distanceTo(ae->getStartpoint())<1.0e-6 && node1.distanceTo(ae->getEndpoint())<1.0e-6)) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "nothing to delete", RS_Debug::D_WARNING); return NULL; } } } // check if the start point is involved: bool startpointInvolved = false; if (node1.distanceTo(polyline.getStartpoint())<1.0e-6 || node2.distanceTo(polyline.getStartpoint())<1.0e-6) { startpointInvolved = true; } // check which part of the polyline has to be deleted: bool deleteStart = false; if (polyline.isClosed()) { bool found = false; double length1 = 0.0; double length2 = 0.0; RS_Entity* e=polyline.firstEntity(); if (startpointInvolved) { if (e->isAtomic()) { RS_AtomicEntity* ae = (RS_AtomicEntity*)e; length1+=ae->getLength(); } e = polyline.nextEntity(); } for (; e!=NULL; e=polyline.nextEntity()) { if (e->isAtomic()) { RS_AtomicEntity* ae = (RS_AtomicEntity*)e; if (node1.distanceTo(ae->getStartpoint())<1.0e-6 || node2.distanceTo(ae->getStartpoint())<1.0e-6) { found = !found; } if (found) { length2+=ae->getLength(); } else { length1+=ae->getLength(); } } } if (length1<length2) { deleteStart = true; } else { deleteStart = false; } } RS_Polyline* newPolyline = new RS_Polyline(container); newPolyline->setClosed(polyline.isClosed()); newPolyline->setSelected(polyline.isSelected()); newPolyline->setLayer(polyline.getLayer()); newPolyline->setPen(polyline.getPen()); if (startpointInvolved && deleteStart && polyline.isClosed()) { newPolyline->setNextBulge(0.0); newPolyline->addVertex(polyline.getStartpoint()); } // copy polyline and drop deleted nodes: bool first = true; bool removing = deleteStart; bool done = false; bool nextIsStraight = false; RS_Entity* lastEntity = polyline.lastEntity(); int i=0; double bulge = 0.0; for (RS_Entity* e=polyline.firstEntity(); e!=NULL; e=polyline.nextEntity()) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: entity: %d", i++); RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: removing: %d", (int)removing); if (e->isAtomic()) { RS_AtomicEntity* ae = (RS_AtomicEntity*)e; if (ae->rtti()==RS2::EntityArc) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: arc segment"); bulge = ((RS_Arc*)ae)->getBulge(); } else { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: line segment"); bulge = 0.0; } // last entity is closing entity and will be added below with endPolyline() if (e==lastEntity && polyline.isClosed()) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "dropping last vertex of closed polyline"); continue; } // first vertex (startpoint) if (first) { if (!removing) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: first node: %f/%f", ae->getStartpoint().x, ae->getStartpoint().y); newPolyline->setNextBulge(bulge); newPolyline->addVertex(ae->getStartpoint()); first = false; } } // stop removing nodes: if (removing==true && (node1.distanceTo(ae->getEndpoint())<1.0e-6 || node2.distanceTo(ae->getEndpoint())<1.0e-6)) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "stop removing at: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); removing = false; done = true; if (first==false) { nextIsStraight = true; } } // normal node (not deleted): if (removing==false && (done==false || deleteStart==false)) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "normal vertex found: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); if (nextIsStraight) { bulge = 0.0; nextIsStraight = false; } newPolyline->setNextBulge(bulge); newPolyline->addVertex(ae->getEndpoint()); } // drop deleted node: else { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "deleting vertex: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); } // start to remove nodes from now on: if (done==false && removing==false && (node1.distanceTo(ae->getEndpoint())<1.0e-6 || node2.distanceTo(ae->getEndpoint())<1.0e-6)) { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "start removing at: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); removing = true; } if (done) { done=false; } } else { RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: " "Polyline contains non-atomic entities", RS_Debug::D_WARNING); } } RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: ending polyline"); newPolyline->setNextBulge(polyline.getClosingBulge()); newPolyline->endPolyline(); // add new polyline: RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: adding new polyline"); container->addEntity(newPolyline); if (graphicView!=NULL) { graphicView->deleteEntity(&polyline); graphicView->drawEntity(newPolyline); } RS_DEBUG->print("RS_Modification::deletePolylineNodesBetween: handling undo"); if (document!=NULL && handleUndo) { document->startUndoCycle(); polyline.setUndoState(true); document->addUndoable(&polyline); document->addUndoable(newPolyline); document->endUndoCycle(); } return newPolyline;}*//** * Trims two segments of a polyline all nodes between the two trim segments * are removed. * * @param polyline The polyline entity. * @param segment1 First segment to trim. * @param segment2 Second segment to trim. * * @return Pointer to the new polyline or NULL. *//*RS_Polyline* RS_Modification::polylineTrim(RS_Polyline& polyline, RS_AtomicEntity& segment1, RS_AtomicEntity& segment2) { RS_DEBUG->print("RS_Modification::polylineTrim"); if (container==NULL) { RS_DEBUG->print("RS_Modification::addPolylineNodesBetween: no valid container", RS_Debug::D_WARNING); return NULL; } if (segment1.getParent()!=&polyline || segment2.getParent()!=&polyline) { RS_DEBUG->print("RS_Modification::polylineTrim: " "segments not in polyline", RS_Debug::D_WARNING); return NULL; } if (&segment1==&segment2) { RS_DEBUG->print("RS_Modification::polylineTrim: " "segments are identical", RS_Debug::D_WARNING); return NULL; } RS_VectorSolutions sol; sol = RS_Information::getIntersection(&segment1, &segment2, false); if (sol.getNumber()==0) { RS_DEBUG->print("RS_Modification::polylineTrim: " "segments cannot be trimmed", RS_Debug::D_WARNING); return NULL; } // check which segment comes first in the polyline: RS_AtomicEntity* firstSegment; if (polyline.findEntity(&segment1) > polyline.findEntity(&segment2)) { firstSegment = &segment2; } else { firstSegment = &segment1; } // find out if we need to trim towards the open part of the polyline bool reverseTrim; reverseTrim = !RS_Math::isSameDirection(firstSegment->getDirection1(), firstSegment->getStartpoint().angleTo(sol.get(0)), M_PI/2.0); //reverseTrim = reverseTrim || !RS_Math::isSameDirection(segment2.getDirection1(), // segment2.getStartpoint().angleTo(sol.get(0)), M_PI/2.0); RS_Polyline* newPolyline = new RS_Polyline(container); newPolyline->setClosed(polyline.isClosed()); newPolyline->setSelected(polyline.isSelected()); newPolyline->setLayer(polyline.getLayer()); newPolyline->setPen(polyline.getPen()); // normal trimming: start removing nodes at trim segment. ends stay the same if (reverseTrim==false) { // copy polyline, trim segments and drop between nodes: bool first = true; bool removing = false; bool nextIsStraight = false; RS_Entity* lastEntity = polyline.lastEntity(); for (RS_Entity* e=polyline.firstEntity(); e!=NULL; e=polyline.nextEntity()) { if (e->isAtomic()) { RS_AtomicEntity* ae = (RS_AtomicEntity*)e; double bulge = 0.0; if (ae->rtti()==RS2::EntityArc) { RS_DEBUG->print("RS_Modification::polylineTrim: arc segment"); bulge = ((RS_Arc*)ae)->getBulge(); } else { RS_DEBUG->print("RS_Modification::polylineTrim: line segment"); bulge = 0.0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -