📄 rs_modification.cpp
字号:
//bc->scale(bc->getBasePoint(), RS_Vector(factor, factor)); // scale block but don't scale inserts in block // (they already scale with their block) for(uint i2=0; i2<bc->count(); ++i2) { RS_Entity* e = bc->entityAt(i2); if (e!=NULL && e->rtti()!=RS2::EntityInsert) { e->scale(bc->getBasePoint(), RS_Vector(factor, factor)); } else { RS_Vector ip = ((RS_Insert*)e)->getInsertionPoint(); ip.scale(bc->getBasePoint(), RS_Vector(factor, factor)); ((RS_Insert*)e)->setInsertionPoint(ip); e->update(); } } graphic->addBlock(bc); } } } } // add entities to this host (graphic or a new block) RS_EntityContainer* host = container; RS_String blockName; // create new block: if (graphic!=NULL) { if (data.asInsert==true) { RS_BlockList* blkList = graphic->getBlockList(); if (blkList!=NULL) { blockName = blkList->newName(data.blockName); RS_Block* blk = new RS_Block(graphic, RS_BlockData(blockName, RS_Vector(0.0,0.0), false)); graphic->addBlock(blk); host = blk; } } } // insert entities: //for (uint i=0; i<((RS_EntityContainer*)source)->count(); ++i) { //RS_Entity* e = source->entityAt(i); for (RS_Entity* e=((RS_EntityContainer*)source)->firstEntity(); e!=NULL; e=((RS_EntityContainer*)source)->nextEntity()) { if (e!=NULL) { RS_String layerName = "0"; RS_Layer* layer = e->getLayer(); if (layer!=NULL) { layerName = layer->getName(); } RS_Entity* e2 = e->clone(); e2->reparent(host); if (data.asInsert==false) { e2->move(data.insertionPoint); } // don't adjust insert factor - block was already adjusted to unit if (e2->rtti()==RS2::EntityInsert) { RS_Vector ip = ((RS_Insert*)e2)->getInsertionPoint(); ip.scale(data.insertionPoint, RS_Vector(factor, factor)); ((RS_Insert*)e2)->setInsertionPoint(ip); e2->update(); } else { e2->scale(data.insertionPoint, RS_Vector(factor, factor)); } host->addEntity(e2); e2->setLayer(layerName); // make sure all sub entities point to layers of the container if (e2->isContainer()) { RS_EntityContainer* ec = (RS_EntityContainer*)e2; for (RS_Entity* e3 = ec->firstEntity(RS2::ResolveAll); e3!=NULL; e3 = ec->nextEntity(RS2::ResolveAll)) { //RS_Entity* e3 = ec->entityAt(i); RS_Layer* l2 = e3->getLayer(); if (l2!=NULL) { e3->setLayer(l2->getName()); } } } if (document!=NULL && data.asInsert==false) { document->addUndoable(e2); } } } if (data.asInsert==true) { RS_Insert* ins = new RS_Insert(container, RS_InsertData( blockName, data.insertionPoint, RS_Vector(data.factor, data.factor), data.angle, 1,1,RS_Vector(0.0,0.0))); container->addEntity(ins); ins->setLayerToActive(); ins->setPenToActive(); if (document!=NULL) { document->addUndoable(ins); } } if (document!=NULL) { document->endUndoCycle(); }}/** * Splits a polyline into two leaving out a gap. * * @param polyline The original polyline * @param e1 1st entity on which the first cutting point is. * @param v1 1st cutting point. * @param e2 2nd entity on which the first cutting point is. * @param v2 2nd cutting point. * @param polyline1 Pointer to a polyline pointer which will hold the * 1st resulting new polyline. Pass NULL if you don't * need those pointers. * @param polyline2 Pointer to a polyline pointer which will hold the * 2nd resulting new polyline. Pass NULL if you don't * need those pointers. * * @todo Support arcs in polylines, check for wrong parameters * * @return true */bool RS_Modification::splitPolyline(RS_Polyline& polyline, RS_Entity& e1, RS_Vector v1, RS_Entity& e2, RS_Vector v2, RS_Polyline** polyline1, RS_Polyline** polyline2) const { if (container==NULL) { RS_DEBUG->print("RS_Modification::splitPolyline: no valid container", RS_Debug::D_WARNING); return false; } RS_Entity* firstEntity = polyline.firstEntity(); RS_Vector firstPoint(false); if (firstEntity->rtti()==RS2::EntityLine) { firstPoint = ((RS_Line*)firstEntity)->getStartpoint(); } RS_Polyline* pl1 = new RS_Polyline(container, RS_PolylineData(firstPoint, RS_Vector(0.0,0.0), 0)); RS_Polyline* pl2 = new RS_Polyline(container); RS_Polyline* pl = pl1; // Current polyline RS_Line* line = NULL; RS_Arc* arc = NULL; if (polyline1!=NULL) { *polyline1 = pl1; } if (polyline2!=NULL) { *polyline2 = pl2; } for (RS_Entity* e = polyline.firstEntity(); e != NULL; e = polyline.nextEntity()) { if (e->rtti()==RS2::EntityLine) { line = (RS_Line*)e; arc = NULL; } else if (e->rtti()==RS2::EntityArc) { arc = (RS_Arc*)e; line = NULL; } else { line = NULL; arc = NULL; } if (line!=NULL /*|| arc!=NULL*/) { if (e==&e1 && e==&e2) { // Trim within a single entity: RS_Vector sp = line->getStartpoint(); double dist1 = (v1-sp).magnitude(); double dist2 = (v2-sp).magnitude(); pl->addVertex(dist1<dist2 ? v1 : v2, 0.0); pl = pl2; pl->setStartpoint(dist1<dist2 ? v2 : v1); pl->addVertex(line->getEndpoint(), 0.0); } else if (e==&e1 || e==&e2) { // Trim entities: RS_Vector v = (e==&e1 ? v1 : v2); if (pl==pl1) { // Trim endpoint of entity to first vector pl->addVertex(v, 0.0); pl = NULL; } else { // Trim startpoint of entity to second vector pl = pl2; pl->setStartpoint(v); pl->addVertex(line->getEndpoint(), 0.0); } } else { // Add entities to polylines if (line!=NULL && pl!=NULL) { pl->addVertex(line->getEndpoint(), 0.0); } } } } container->addEntity(pl1); container->addEntity(pl2); //container->removeEntity(&polyline); polyline.changeUndoState(); return true;}/** * Adds a node to the given polyline. The new node is placed between * the start and end point of the given segment. * * @param node The position of the new node. * * @return Pointer to the new polyline or NULL. *//*RS_Polyline* RS_Modification::addPolylineNode(RS_Polyline& polyline, const RS_AtomicEntity& segment, const RS_Vector& node) { RS_DEBUG->print("RS_Modification::addPolylineNode"); if (container==NULL) { RS_DEBUG->print("RS_Modification::addPolylineNode: no valid container", RS_Debug::D_WARNING); return NULL; } if (segment.getParent()!=&polyline) { RS_DEBUG->print("RS_Modification::addPolylineNode: " "segment not part of the polyline", RS_Debug::D_WARNING); return NULL; } RS_Polyline* newPolyline = new RS_Polyline(container); newPolyline->setClosed(polyline.isClosed()); newPolyline->setSelected(polyline.isSelected()); newPolyline->setLayer(polyline.getLayer()); newPolyline->setPen(polyline.getPen()); // copy polyline and add new node: bool first = true; 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::addPolylineNode: arc segment"); bulge = ((RS_Arc*)ae)->getBulge(); } else { RS_DEBUG->print("RS_Modification::addPolylineNode: line segment"); bulge = 0.0; } if (first) { RS_DEBUG->print("RS_Modification::addPolylineNode: first segment: %f/%f", ae->getStartpoint().x, ae->getStartpoint().y); newPolyline->setNextBulge(bulge); newPolyline->addVertex(ae->getStartpoint()); first = false; } // segment to split: if (ae==&segment) { RS_DEBUG->print("RS_Modification::addPolylineNode: split segment found"); RS_DEBUG->print("RS_Modification::addPolylineNode: node: %f/%f", node.x, node.y); newPolyline->setNextBulge(0.0); newPolyline->addVertex(node); RS_DEBUG->print("RS_Modification::addPolylineNode: after node: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); if (ae!=lastEntity || polyline.isClosed()==false) { newPolyline->setNextBulge(0.0); newPolyline->addVertex(ae->getEndpoint()); } } else { RS_DEBUG->print("RS_Modification::addPolylineNode: normal vertex found: %f/%f", ae->getEndpoint().x, ae->getEndpoint().y); if (ae!=lastEntity || polyline.isClosed()==false) { newPolyline->setNextBulge(bulge); newPolyline->addVertex(ae->getEndpoint()); } } } else { RS_DEBUG->print("RS_Modification::addPolylineNode: " "Polyline contains non-atomic entities", RS_Debug::D_WARNING); } } newPolyline->setNextBulge(polyline.getClosingBulge()); newPolyline->endPolyline(); // add new polyline: container->addEntity(newPolyline); if (graphicView!=NULL) { graphicView->deleteEntity(&polyline); graphicView->drawEntity(newPolyline); } if (document!=NULL && handleUndo) { document->startUndoCycle(); polyline.setUndoState(true); document->addUndoable(&polyline); document->addUndoable(newPolyline); document->endUndoCycle(); } return newPolyline;}*//** * Deletes a node from a polyline. * * @param node The node to delete. * * @return Pointer to the new polyline or NULL. *//*RS_Polyline* RS_Modification::deletePolylineNode(RS_Polyline& polyline, const RS_Vector& node) { RS_DEBUG->print("RS_Modification::deletePolylineNode"); if (container==NULL) { RS_DEBUG->print("RS_Modification::addPolylineNode: no valid container", RS_Debug::D_WARNING); return NULL; } if (node.valid==false) { RS_DEBUG->print("RS_Modification::deletePolylineNode: " "node not valid", RS_Debug::D_WARNING); return NULL; } // check if the polyline is no longer there after deleting the node: if (polyline.count()==1) { RS_Entity* e = polyline.firstEntity(); if (e!=NULL && e->isAtomic()) { RS_AtomicEntity* ae = (RS_AtomicEntity*)e; if (node.distanceTo(ae->getStartpoint())<1.0e-6 || node.distanceTo(ae->getEndpoint())<1.0e-6) { if (graphicView!=NULL) { graphicView->deleteEntity(&polyline); } if (document!=NULL && handleUndo) { document->startUndoCycle(); polyline.setUndoState(true); document->addUndoable(&polyline); document->endUndoCycle(); } } } return NULL; } RS_Polyline* newPolyline = new RS_Polyline(container); newPolyline->setClosed(polyline.isClosed()); newPolyline->setSelected(polyline.isSelected()); newPolyline->setLayer(polyline.getLayer()); newPolyline->setPen(polyline.getPen()); // copy polyline and drop deleted node: bool first = true; bool lastDropped = false; RS_Entity* lastEntity = polyline.lastEntity(); for (RS_Entity* e=polyline.firstEntity(); e!=NULL; e=polyline.nextEntity()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -