/** * Shows a dialog for adding a block. Doesn't add the block. * This is up to the caller. * * @return a pointer to the newly created block that * should be added. */ RS_BlockData QG_DialogFactory::requestNewBlockDialog(RS_BlockList* blockList) { //RS_Block* block = nullptr; RS_BlockData ret; ret = RS_BlockData("", RS_Vector(false), false); if (!blockList) { RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestNewBlockDialog(): " "blockList is nullptr"); return ret; } // Block for parameter livery //block = new RS_Block(container, "noname", RS_Vector(0.0,0.0)); QG_BlockDialog dlg(parent); dlg.setBlockList(blockList); if (dlg.exec()) { ret = dlg.getBlockData(); } return ret; }
/** * Shows a dialog for renaming the currently active block. * * @return a pointer to the modified block or nullptr on cancellation. */ RS_BlockData QG_DialogFactory::requestBlockAttributesDialog(RS_BlockList* blockList) { //RS_Block* block = nullptr; RS_BlockData ret; ret = RS_BlockData("", RS_Vector(false), false); if (!blockList) { RS_DEBUG->print(RS_Debug::D_WARNING, "QG_DialogFactory::requestBlockAttributesDialog(): " "blockList is nullptr"); return ret; } /* if (!blockList) { if (container && container->rtti()==RS2::EntityGraphic) { blockList = (RS_BlockList*)container; } else { return nullptr; } }*/ // Block for parameter livery //block = blockList->getActive(); QG_BlockDialog dlg(parent, "Rename Block"); dlg.setBlockList(blockList); if (dlg.exec()) { //dlg.updateBlock(); //block->setData(); ret = dlg.getBlockData(); } //else { // ret = RS_BlockData("", RS_Vector(false)); //} return ret; }
/** * Creates a new block from the currently selected entitiies. * * @param referencePoint Reference point for the block. * @param name Block name * @param remove true: remove existing entities, false: don't touch entities */ RS_Block* RS_Creation::createBlock(const RS_BlockData* data, const RS_Vector& referencePoint, const bool remove) { // start undo cycle for the container if we're deleting the existing entities if (remove && document) { document->startUndoCycle(); } RS_Block* block = new RS_Block(container, RS_BlockData(*data)); // copy entities into a block for(auto e: *container){ //for (unsigned i=0; i<container->count(); ++i) { //RS_Entity* e = container->entityAt(i); if (e && e->isSelected()) { // delete / redraw entity in graphic view: if (remove) { if (graphicView) { graphicView->deleteEntity(e); } e->setSelected(false); } else { if (graphicView) { graphicView->deleteEntity(e); } e->setSelected(false); if (graphicView) { graphicView->drawEntity(e); } } // add entity to block: RS_Entity* c = e->clone(); c->move(-referencePoint); block->addEntity(c); if (remove) { //container->removeEntity(e); //i=0; e->changeUndoState(); if (document) { document->addUndoable(e); } } } } if (remove && document) { document->endUndoCycle(); } if (graphic) { graphic->addBlock(block); } return block; }
/** * Testing function. */ void LC_SimpleTests::slotTestInsertBlock() { RS_DEBUG->print("%s\n: begin\n", __func__); auto appWin=QC_ApplicationWindow::getAppWindow(); RS_Document* d = appWin->getDocument(); if (d && d->rtti()==RS2::EntityGraphic) { RS_Graphic* graphic = (RS_Graphic*)d; if (graphic==NULL) { return; } graphic->addLayer(new RS_Layer("default")); RS_Block* block = new RS_Block(graphic, RS_BlockData("debugblock", RS_Vector(0.0,0.0), true)); RS_Line* line; RS_Arc* arc; RS_Circle* circle; // Add one red line: line = new RS_Line{block, {0.,0.}, {50.,0.}}; line->setLayerToActive(); line->setPen(RS_Pen(RS_Color(255, 0, 0), RS2::Width01, RS2::SolidLine)); block->addEntity(line); // Add one line with attributes from block: line = new RS_Line{block, {50.,0.}, {50.,50.}}; line->setPen(RS_Pen(RS_Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock)); block->addEntity(line); // Add one arc with attributes from block: RS_ArcData d({50.,0.}, 50.0, M_PI_2, M_PI, false); arc = new RS_Arc(block, d); arc->setPen(RS_Pen(RS_Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock)); block->addEntity(arc); // Add one blue circle: RS_CircleData circleData(RS_Vector(20.0,15.0), 12.5); circle = new RS_Circle(block, circleData); circle->setLayerToActive(); circle->setPen(RS_Pen(RS_Color(0, 0, 255), RS2::Width01, RS2::SolidLine)); block->addEntity(circle); graphic->addBlock(block); RS_Insert* ins; RS_InsertData insData("debugblock", RS_Vector(0.0,0.0), RS_Vector(1.0,1.0), 0.0, 1, 1, RS_Vector(0.0, 0.0), NULL, RS2::NoUpdate); // insert one magenta instance of the block (original): ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(255, 0, 255), RS2::Width02, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); // insert one green instance of the block (rotate): insData = RS_InsertData("debugblock", RS_Vector(-50.0,20.0), RS_Vector(1.0,1.0), M_PI/6., 1, 1, RS_Vector(0.0, 0.0), NULL, RS2::NoUpdate); ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(0, 255, 0), RS2::Width02, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); // insert one cyan instance of the block (move): insData = RS_InsertData("debugblock", RS_Vector(10.0,20.0), RS_Vector(1.0,1.0), 0.0, 1, 1, RS_Vector(0.0, 0.0), NULL, RS2::NoUpdate); ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width02, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); // insert one blue instance of the block: for (double a=0.0; a<360.0; a+=45.0) { insData = RS_InsertData("debugblock", RS_Vector(60.0,0.0), RS_Vector(2.0/5,2.0/5), RS_Math::deg2rad(a), 1, 1, RS_Vector(0.0, 0.0), NULL, RS2::NoUpdate); ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(0, 0, 255), RS2::Width05, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); } // insert an array of yellow instances of the block: insData = RS_InsertData("debugblock", RS_Vector(-100.0,-100.0), RS_Vector(0.2,0.2), M_PI/6.0, 6, 4, RS_Vector(100.0, 100.0), NULL, RS2::NoUpdate); ins = new RS_Insert(graphic, insData); ins->setLayerToActive(); ins->setPen(RS_Pen(RS_Color(255, 255, 0), RS2::Width01, RS2::SolidLine)); ins->update(); graphic->addEntity(ins); RS_GraphicView* v = appWin->getGraphicView(); if (v) { v->redraw(); } } RS_DEBUG->print("%s\n: end\n", __func__); }
RS_BlockData QG_BlockDialog::getBlockData() { return RS_BlockData(leName->text(), RS_Vector(0.0,0.0), false); }