📄 rs_modification.cpp
字号:
// last entity is closing entity and will be added below with endPolyline() if (e==lastEntity && polyline.isClosed()) { RS_DEBUG->print("RS_Modification::polylineTrim: " "dropping last vertex of closed polyline"); continue; } // first vertex (startpoint) if (first) { RS_DEBUG->print("RS_Modification::polylineTrim: first node: %f/%f", ae->getStartpoint().x, ae->getStartpoint().y); newPolyline->setNextBulge(bulge); newPolyline->addVertex(ae->getStartpoint()); first = false; } // trim and start removing nodes: if (removing==false && (ae==&segment1 || ae==&segment2)) { RS_DEBUG->print("RS_Modification::polylineTrim: " "start removing at trim point %f/%f", sol.get(0).x, sol.get(0).y); newPolyline->setNextBulge(0.0); newPolyline->addVertex(sol.get(0)); removing = true; nextIsStraight = true; } // stop removing nodes: else if (removing==true && (ae==&segment1 || ae==&segment2)) { RS_DEBUG->print("RS_Modification::polylineTrim: stop removing at: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); removing = false; } // normal node (not deleted): if (removing==false) { RS_DEBUG->print("RS_Modification::polylineTrim: normal vertex found: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); if (nextIsStraight) { newPolyline->setNextBulge(0.0); nextIsStraight = false; } else { newPolyline->setNextBulge(bulge); } newPolyline->addVertex(ae->getEndpoint()); } } else { RS_DEBUG->print("RS_Modification::polylineTrim: " "Polyline contains non-atomic entities", RS_Debug::D_WARNING); } } } // reverse trimming: remove nodes at the ends and keep those in between else { // copy polyline, trim segments and drop between nodes: //bool first = true; bool removing = true; 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; } // last entity is closing entity and will be added below with endPolyline() if (e==lastEntity && polyline.isClosed()) { RS_DEBUG->print("RS_Modification::polylineTrim: " "dropping last vertex of closed polyline"); continue; } // trim and stop removing nodes: if (removing==true && (ae==&segment1 || ae==&segment2)) { RS_DEBUG->print("RS_Modification::polylineTrim: " "stop removing at trim point %f/%f", sol.get(0).x, sol.get(0).y); newPolyline->setNextBulge(0.0); // start of new polyline: newPolyline->addVertex(sol.get(0)); removing = false; nextIsStraight = true; } // start removing nodes again: else if (removing==false && (ae==&segment1 || ae==&segment2)) { RS_DEBUG->print("RS_Modification::polylineTrim: start removing at: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); newPolyline->setNextBulge(0.0); // start of new polyline: newPolyline->addVertex(sol.get(0)); removing = true; } // normal node (not deleted): if (removing==false) { RS_DEBUG->print("RS_Modification::polylineTrim: normal vertex found: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); if (nextIsStraight) { newPolyline->setNextBulge(0.0); nextIsStraight = false; } else { newPolyline->setNextBulge(bulge); } newPolyline->addVertex(ae->getEndpoint()); } } else { RS_DEBUG->print("RS_Modification::polylineTrim: " "Polyline contains non-atomic entities", RS_Debug::D_WARNING); } } } RS_DEBUG->print("RS_Modification::polylineTrim: ending polyline"); newPolyline->setNextBulge(polyline.getClosingBulge()); newPolyline->endPolyline(); // add new polyline: RS_DEBUG->print("RS_Modification::polylineTrim: adding new polyline"); container->addEntity(newPolyline); if (graphicView!=NULL) { graphicView->deleteEntity(&polyline); graphicView->drawEntity(newPolyline); } RS_DEBUG->print("RS_Modification::polylineTrim: handling undo"); if (document!=NULL && handleUndo) { document->startUndoCycle(); polyline.setUndoState(true); document->addUndoable(&polyline); document->addUndoable(newPolyline); document->endUndoCycle(); } return newPolyline;}*//** * Moves all selected entities with the given data for the move * modification. */bool RS_Modification::move(RS_MoveData& data) { if (container==NULL) { RS_DEBUG->print("RS_Modification::move: no valid container", RS_Debug::D_WARNING); return false; } RS_PtrList<RS_Entity> addList; addList.setAutoDelete(false); if (document!=NULL && handleUndo) { document->startUndoCycle(); } // Create new entites for (int num=1; num<=data.number || (data.number==0 && num<=1); num++) { // too slow: //for (uint i=0; i<container->count(); ++i) { //RS_Entity* e = container->entityAt(i); for (RS_Entity* e=container->firstEntity(); e!=NULL; e=container->nextEntity()) { if (e!=NULL && e->isSelected()) { RS_Entity* ec = e->clone(); ec->move(data.offset*num); if (data.useCurrentLayer) { ec->setLayerToActive(); } if (data.useCurrentAttributes) { ec->setPenToActive(); } if (ec->rtti()==RS2::EntityInsert) { ((RS_Insert*)ec)->update(); } // since 2.0.4.0: keep selection ec->setSelected(true); addList.append(ec); } } } deselectOriginals(data.number==0); addNewEntities(addList); if (document!=NULL && handleUndo) { document->endUndoCycle(); } if (graphicView!=NULL) { graphicView->redraw(); } return true;}/** * Rotates all selected entities with the given data for the rotation. */bool RS_Modification::rotate(RS_RotateData& data) { if (container==NULL) { RS_DEBUG->print("RS_Modification::rotate: no valid container", RS_Debug::D_WARNING); return false; } RS_PtrList<RS_Entity> addList; addList.setAutoDelete(false); if (document!=NULL && handleUndo) { document->startUndoCycle(); } // Create new entites for (int num=1; num<=data.number || (data.number==0 && num<=1); num++) { for (RS_Entity* e=container->firstEntity(); e!=NULL; e=container->nextEntity()) { //for (uint i=0; i<container->count(); ++i) { //RS_Entity* e = container->entityAt(i); if (e!=NULL && e->isSelected()) { RS_Entity* ec = e->clone(); ec->setSelected(false); ec->rotate(data.center, data.angle*num); if (data.useCurrentLayer) { ec->setLayerToActive(); } if (data.useCurrentAttributes) { ec->setPenToActive(); } if (ec->rtti()==RS2::EntityInsert) { ((RS_Insert*)ec)->update(); } addList.append(ec); } } } deselectOriginals(data.number==0); addNewEntities(addList); if (document!=NULL && handleUndo) { document->endUndoCycle(); } if (graphicView!=NULL) { graphicView->redraw(); } return true;}/** * Moves all selected entities with the given data for the scale * modification. */bool RS_Modification::scale(RS_ScaleData& data) { if (container==NULL) { RS_DEBUG->print("RS_Modification::scale: no valid container", RS_Debug::D_WARNING); return false; } RS_PtrList<RS_Entity> addList; addList.setAutoDelete(false); if (document!=NULL && handleUndo) { document->startUndoCycle(); } // Create new entites for (int num=1; num<=data.number || (data.number==0 && num<=1); num++) { for (RS_Entity* e=container->firstEntity(); e!=NULL; e=container->nextEntity()) { //for (uint i=0; i<container->count(); ++i) { //RS_Entity* e = container->entityAt(i); if (e!=NULL && e->isSelected()) { RS_Entity* ec = e->clone(); ec->setSelected(false); ec->scale(data.referencePoint, RS_Math::pow(data.factor, num)); if (data.useCurrentLayer) { ec->setLayerToActive(); } if (data.useCurrentAttributes) { ec->setPenToActive(); } if (ec->rtti()==RS2::EntityInsert) { ((RS_Insert*)ec)->update(); } addList.append(ec); } } } deselectOriginals(data.number==0); addNewEntities(addList); if (document!=NULL && handleUndo) { document->endUndoCycle(); } if (graphicView!=NULL) { graphicView->redraw(); } return true;}/** * Mirror all selected entities with the given data for the mirror * modification. */bool RS_Modification::mirror(RS_MirrorData& data) { if (container==NULL) { RS_DEBUG->print("RS_Modification::mirror: no valid container", RS_Debug::D_WARNING); return false; } RS_PtrList<RS_Entity> addList; addList.setAutoDelete(false); if (document!=NULL && handleUndo) { document->startUndoCycle(); } // Create new entites for (int num=1; num<=(int)data.copy || (data.copy==false && num<=1); num++) { for (RS_Entity* e=container->firstEntity(); e!=NULL; e=container->nextEntity()) { //for (uint i=0; i<container->count(); ++i) { //RS_Entity* e = container->entityAt(i); if (e!=NULL && e->isSelected()) { RS_Entity* ec = e->clone(); ec->setSelected(false); ec->mirror(data.axisPoint1, data.axisPoint2); if (data.useCurrentLayer) { ec->setLayerToActive(); } if (data.useCurrentAttributes) { ec->setPenToActive(); } if (ec->rtti()==RS2::EntityInsert) { ((RS_Insert*)ec)->update(); } addList.append(ec); } } } deselectOriginals(data.copy==false); addNewEntities(addList); if (document!=NULL && handleUndo) { document->endUndoCycle(); } if (graphicView!=NULL) { graphicView->redraw(); } return true;}/** * Rotates entities around two centers with the given parameters. */bool RS_Modification::rotate2(RS_Rotate2Data& data) { if (container==NULL) { RS_DEBUG->print("RS_Modification::rotate2: no valid container", RS_Debug::D_WARNING);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -