📄 rs_modification.cpp
字号:
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.center1, data.angle1*num); RS_Vector center2 = data.center2; center2.rotate(data.center1, data.angle1*num); ec->rotate(center2, data.angle2*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 and rotates entities with the given parameters. */bool RS_Modification::moveRotate(RS_MoveRotateData& data) { if (container==NULL) { RS_DEBUG->print("RS_Modification::moveRotate: 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->move(data.offset*num); ec->rotate(data.referencePoint + data.offset*num, 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;}/** * Deselects all selected entities and removes them if remove is true; * * @param remove true: Remove entites. */void RS_Modification::deselectOriginals(bool remove ) { 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) { bool selected = false; /* if (e->isAtomic()) { RS_AtomicEntity* ae = (RS_AtomicEntity*)e; if (ae->isStartpointSelected() || ae->isEndpointSelected()) { selected = true; } } */ if (e->isSelected()) { selected = true; } if (selected) { e->setSelected(false); if (remove ) { //if (graphicView!=NULL) { // graphicView->deleteEntity(e); //} e->changeUndoState(); if (document!=NULL && handleUndo) { document->addUndoable(e); } } else { //if (graphicView!=NULL) { // graphicView->drawEntity(e); //} } } } }}/** * Adds the given entities to the container and draws the entities if * there's a graphic view available. * * @param addList Entities to add. */void RS_Modification::addNewEntities(RS_PtrList<RS_Entity>& addList) { for (RS_Entity* e=addList.first(); e!=NULL; e=addList.next()) { if (e!=NULL) { container->addEntity(e); if (document!=NULL && handleUndo) { document->addUndoable(e); } //if (graphicView!=NULL) { // graphicView->drawEntity(e); //} } }}/** * Trims or extends the given trimEntity to the intersection point of the * trimEntity and the limitEntity. * * @param trimCoord Coordinate which defines which endpoint of the * trim entity to trim. * @param trimEntity Entity which will be trimmed. * @param limitCoord Coordinate which defines the intersection to which the * trim entity will be trimmed. * @param limitEntity Entity to which the trim entity will be trimmed. * @param both true: Trim both entities. false: trim trimEntity only. */bool RS_Modification::trim(const RS_Vector& trimCoord, RS_AtomicEntity* trimEntity, const RS_Vector& limitCoord, RS_Entity* limitEntity, bool both) { if (trimEntity==NULL || limitEntity==NULL) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Modification::trim: At least one entity is NULL"); return false; } if (both && !limitEntity->isAtomic()) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Modification::trim: limitEntity is not atomic"); } RS_VectorSolutions sol; if (limitEntity->isAtomic()) { // intersection(s) of the two entities: sol = RS_Information::getIntersection(trimEntity, limitEntity, false); } else if (limitEntity->isContainer()) { RS_EntityContainer* ec = (RS_EntityContainer*)limitEntity; sol.alloc(128); int i=0; for (RS_Entity* e=ec->firstEntity(RS2::ResolveAll); e!=NULL; e=ec->nextEntity(RS2::ResolveAll)) { //for (int i=0; i<container->count(); ++i) { // RS_Entity* e = container->entityAt(i); if (e!=NULL) { RS_VectorSolutions s2 = RS_Information::getIntersection(trimEntity, e, false); if (s2.hasValid()) { for (int k=0; k<s2.getNumber(); ++k) { if (i<128 && s2.get(k).valid) { if (e->isPointOnEntity(s2.get(k), 1.0e-4)) { sol.set(i++, s2.get(k)); } } } //break; } } } } if (sol.hasValid()==false) { return false; } RS_AtomicEntity* trimmed1 = NULL; RS_AtomicEntity* trimmed2 = NULL; // remove trim entity from view: if (trimEntity->rtti()==RS2::EntityCircle) { // convert a circle into a trimmable arc RS_Circle* c = (RS_Circle*)trimEntity; double am = c->getCenter().angleTo(trimCoord); RS_ArcData d(c->getCenter(), c->getRadius(), RS_Math::correctAngle(am-M_PI/2), RS_Math::correctAngle(am+M_PI/2), false); trimmed1 = new RS_Arc(trimEntity->getParent(), d); } else { trimmed1 = (RS_AtomicEntity*)trimEntity->clone(); trimmed1->setHighlighted(false); } if (graphicView!=NULL) { graphicView->deleteEntity(trimEntity); } // remove limit entity from view: if (both) { trimmed2 = (RS_AtomicEntity*)limitEntity->clone(); trimmed2->setHighlighted(false); if (graphicView!=NULL) { graphicView->deleteEntity(limitEntity); } } // trim trim entity int ind = 0; RS_Vector is = sol.getClosest(limitCoord, NULL, &ind); //sol.getClosest(limitCoord, NULL, &ind); RS_DEBUG->print("RS_Modification::trim: limitCoord: %f/%f", limitCoord.x, limitCoord.y); RS_DEBUG->print("RS_Modification::trim: sol.get(0): %f/%f", sol.get(0).x, sol.get(0).y); RS_DEBUG->print("RS_Modification::trim: sol.get(1): %f/%f", sol.get(1).x, sol.get(1).y); RS_DEBUG->print("RS_Modification::trim: ind: %d", ind); RS_Vector is2 = sol.get(ind==0 ? 1 : 0); //RS_Vector is2 = sol.get(ind); RS_DEBUG->print("RS_Modification::trim: is2: %f/%f", is2.x, is2.y); //RS2::Ending ending = trimmed1->getTrimPoint(trimCoord, is); RS2::Ending ending = trimmed1->getTrimPoint(trimCoord, is); switch (ending) { case RS2::EndingStart: trimmed1->trimStartpoint(is); if (trimEntity->rtti()==RS2::EntityCircle) { trimmed1->trimEndpoint(is2); } break; case RS2::EndingEnd: trimmed1->trimEndpoint(is); if (trimEntity->rtti()==RS2::EntityCircle) { trimmed1->trimStartpoint(is2); } break; default: break; } // trim limit entity: if (both) { RS_Vector is = sol.getClosest(limitCoord); RS2::Ending ending = trimmed2->getTrimPoint(limitCoord, is); switch (ending) { case RS2::EndingStart: trimmed2->trimStartpoint(is); break; case RS2::EndingEnd: trimmed2->trimEndpoint(is); break; default: break; } } // add new trimmed trim entity: container->addEntity(trimmed1); if (graphicView!=NULL) { graphicView->drawEntity(trimmed1); } // add new trimmed limit entity: if (both) { container->addEntity(trimmed2); if (graphicView!=NULL) { graphicView->drawEntity(trimmed2); } } if (document!=NULL && handleUndo) { document->startUndoCycle(); document->addUndoable(trimmed1); trimEntity->setUndoState(true); document->addUndoable(trimEntity); if (both) { document->addUndoable(trimmed2); limitEntity->setUndoState(true); document->addUndoable(limitEntity); } document->endUndoCycle(); } return true;}/** * Trims or extends the given trimEntity by the given amount. * * @param trimCoord Coordinate which defines which endpoint of the * trim entity to trim. * @param trimEntity Entity which will be trimmed. * @param dist Amount to trim by. */bool RS_Modification::trimAmount(const RS_Vector& trimCoord, RS_AtomicEntity* trimEntity, double dist) { if (trimEntity==NULL) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Modification::trimAmount: Entity is NULL"); return false; } RS_AtomicEntity* trimmed = NULL; // remove trim entity: trimmed = (RS_AtomicEntity*)trimEntity->clone(); if (graphicView!=NULL) { graphicView->deleteEntity(trimEntity); } // trim trim entity RS_Vector is = trimmed->getNearestDist(-dist, trimCoord); if (trimCoord.distanceTo(trimmed->getStartpoint()) <
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -