| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "rs_actionblockssave.h" |
| |
|
| | #include <QApplication> |
| |
|
| | #include "lc_documentsstorage.h" |
| | #include "lc_containertraverser.h" |
| | #include "qc_applicationwindow.h" |
| | #include "qc_mdiwindow.h" |
| | #include "qg_blockwidget.h" |
| | #include "qg_filedialog.h" |
| | #include "rs_block.h" |
| | #include "rs_debug.h" |
| | #include "rs_graphic.h" |
| | #include "rs_insert.h" |
| |
|
| | class RS_Block; |
| | |
| | RS_ActionBlocksSave::RS_ActionBlocksSave(LC_ActionContext *actionContext) |
| | :RS_ActionInterface("Edit Block", actionContext, RS2::ActionBlocksSave) {} |
| |
|
| | |
| | void RS_ActionBlocksSave::addBlock(RS_Insert *in, RS_Graphic *g) { |
| | for (auto e: *in) { |
| | if (e->rtti() == RS2::EntityInsert) { |
| | auto *insert = static_cast<RS_Insert *>(e); |
| | addBlock(insert, g); |
| | g->addBlock(insert->getBlockForInsert()); |
| | } |
| | } |
| | } |
| |
|
| | |
| | RS_Graphic* RS_ActionBlocksSave::createGraphicForBlock(RS_Block *activeBlock){ |
| | auto* result = new RS_Graphic(); |
| | result->setOwner(false); |
| | result->getBlockList()->setOwner(false); |
| | result->clearLayers(); |
| | |
| |
|
| | for (RS_Entity* e : lc::LC_ContainerTraverser{*activeBlock, RS2::ResolveNone}.entities()) { |
| | result->addEntity(e); |
| | if (e->rtti() == RS2::EntityInsert) { |
| | auto *insert = static_cast<RS_Insert *>(e); |
| | result->addBlock(insert->getBlockForInsert()); |
| | addBlock(insert,result); |
| | } |
| | |
| | } |
| | return result; |
| | } |
| |
|
| | void RS_ActionBlocksSave::trigger() { |
| | auto& appWindow = QC_ApplicationWindow::getAppWindow(); |
| | if(!appWindow) { |
| | finish(false); |
| | return; |
| | } |
| | RS_BlockList* blockList = appWindow->getBlockWidget() -> getBlockList(); |
| | if (blockList != nullptr) { |
| | auto activeBlock= blockList->getActive(); |
| | if(activeBlock != nullptr) { |
| | RS2::FormatType format = RS2::FormatDXFRW; |
| | QG_FileDialog dlg(appWindow->getCurrentMDIWindow(), {}, QG_FileDialog::BlockFile); |
| | const QString fileName = dlg.getSaveFile(&format, activeBlock->getName()); |
| | if (fileName.isEmpty()) { |
| | |
| | } |
| | else { |
| | QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); |
| | RS_Graphic* graphic = createGraphicForBlock(activeBlock); |
| | graphic->setModified(true); |
| |
|
| | LC_DocumentsStorage storage; |
| | storage.saveBlockAs(graphic, fileName); |
| |
|
| | delete graphic; |
| | QApplication::restoreOverrideCursor(); |
| | } |
| | } else |
| | commandMessage(tr("No block activated to save")); |
| | } else { |
| | RS_DEBUG->print(RS_Debug::D_WARNING, |
| | "RS_ActionBlocksSave::trigger(): blockList is NULL"); |
| | } |
| | finish(false); |
| | } |
| |
|
| | void RS_ActionBlocksSave::init(int status) { |
| | RS_ActionInterface::init(status); |
| | trigger(); |
| | } |
| |
|