00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QString>
00027 # include <QDir>
00028 # include <QFileInfo>
00029 # include <QLineEdit>
00030 # include <QPointer>
00031 # include <Standard_math.hxx>
00032 # include <TopoDS_Shape.hxx>
00033 # include <Inventor/events/SoMouseButtonEvent.h>
00034 #endif
00035
00036 #include <Base/Console.h>
00037 #include <Base/Exception.h>
00038 #include <App/Document.h>
00039 #include <Gui/Application.h>
00040 #include <Gui/BitmapFactory.h>
00041 #include <Gui/Command.h>
00042 #include <Gui/Control.h>
00043 #include <Gui/Document.h>
00044 #include <Gui/FileDialog.h>
00045 #include <Gui/MainWindow.h>
00046 #include <Gui/Selection.h>
00047 #include <Gui/View3DInventor.h>
00048 #include <Gui/View3DInventorViewer.h>
00049
00050 #include "../App/PartFeature.h"
00051 #include "DlgPartImportStepImp.h"
00052 #include "DlgBooleanOperation.h"
00053 #include "DlgExtrusion.h"
00054 #include "DlgRevolution.h"
00055 #include "DlgFilletEdges.h"
00056 #include "DlgPrimitives.h"
00057 #include "CrossSections.h"
00058 #include "Mirroring.h"
00059 #include "ViewProvider.h"
00060 #include "TaskShapeBuilder.h"
00061 #include "TaskLoft.h"
00062
00063
00064
00065
00066
00067
00068
00069 DEF_STD_CMD(CmdPartPickCurveNet);
00070
00071 CmdPartPickCurveNet::CmdPartPickCurveNet()
00072 :Command("Part_PickCurveNet")
00073 {
00074 sAppModule = "Part";
00075 sGroup = QT_TR_NOOP("Part");
00076 sMenuText = QT_TR_NOOP("Pick curve network");
00077 sToolTipText = QT_TR_NOOP("Pick a curve network");
00078 sWhatsThis = sToolTipText;
00079 sStatusTip = sToolTipText;
00080 sPixmap = "Test1";
00081 }
00082
00083 void CmdPartPickCurveNet::activated(int iMsg)
00084 {
00085
00086 }
00087
00088
00089
00090
00091 DEF_STD_CMD(CmdPartNewDoc);
00092
00093 CmdPartNewDoc::CmdPartNewDoc()
00094 :Command("Part_NewDoc")
00095 {
00096 sAppModule = "Part";
00097 sGroup = "Part";
00098 sMenuText = "New document";
00099 sToolTipText = "Create an empty part document";
00100 sWhatsThis = sToolTipText;
00101 sStatusTip = sToolTipText;
00102 sPixmap = "New";
00103 }
00104
00105 void CmdPartNewDoc::activated(int iMsg)
00106 {
00107 doCommand(Doc,"d = App.New()");
00108 updateActive();
00109 }
00110
00111
00112
00113
00114 DEF_STD_CMD_A(CmdPartBox2);
00115
00116 CmdPartBox2::CmdPartBox2()
00117 :Command("Part_Box2")
00118 {
00119 sAppModule = "Part";
00120 sGroup = QT_TR_NOOP("Part");
00121 sMenuText = QT_TR_NOOP("Box fix 1");
00122 sToolTipText = QT_TR_NOOP("Create a box solid without dialog");
00123 sWhatsThis = "Part_Box2";
00124 sStatusTip = sToolTipText;
00125 sPixmap = "Part_Box";
00126 }
00127
00128
00129 void CmdPartBox2::activated(int iMsg)
00130 {
00131 openCommand("Part Box Create");
00132 doCommand(Doc,"from FreeCAD import Base");
00133 doCommand(Doc,"import Part");
00134 doCommand(Doc,"__fb__ = App.ActiveDocument.addObject(\"Part::Box\",\"PartBox\")");
00135 doCommand(Doc,"__fb__.Location = Base.Vector(0.0,0.0,0.0)");
00136 doCommand(Doc,"__fb__.Length = 100.0");
00137 doCommand(Doc,"__fb__.Width = 100.0");
00138 doCommand(Doc,"__fb__.Height = 100.0");
00139 doCommand(Doc,"del __fb__");
00140 commitCommand();
00141 updateActive();
00142 }
00143
00144 bool CmdPartBox2::isActive(void)
00145 {
00146 if (getActiveGuiDocument())
00147 return true;
00148 else
00149 return false;
00150 }
00151
00152
00153
00154
00155 DEF_STD_CMD_A(CmdPartBox3);
00156
00157 CmdPartBox3::CmdPartBox3()
00158 :Command("Part_Box3")
00159 {
00160 sAppModule = "Part";
00161 sGroup = QT_TR_NOOP("Part");
00162 sMenuText = QT_TR_NOOP("Box fix 2");
00163 sToolTipText = QT_TR_NOOP("Create a box solid without dialog");
00164 sWhatsThis = "Part_Box3";
00165 sStatusTip = sToolTipText;
00166 sPixmap = "Part_Box";
00167 }
00168
00169 void CmdPartBox3::activated(int iMsg)
00170 {
00171 openCommand("Part Box Create");
00172 doCommand(Doc,"from FreeCAD import Base");
00173 doCommand(Doc,"import Part");
00174 doCommand(Doc,"__fb__ = App.ActiveDocument.addObject(\"Part::Box\",\"PartBox\")");
00175 doCommand(Doc,"__fb__.Location = Base.Vector(50.0,50.0,50.0)");
00176 doCommand(Doc,"__fb__.Length = 100.0");
00177 doCommand(Doc,"__fb__.Width = 100.0");
00178 doCommand(Doc,"__fb__.Height = 100.0");
00179 doCommand(Doc,"del __fb__");
00180 commitCommand();
00181 updateActive();
00182 }
00183
00184 bool CmdPartBox3::isActive(void)
00185 {
00186 if (getActiveGuiDocument())
00187 return true;
00188 else
00189 return false;
00190 }
00191
00192
00193
00194
00195 DEF_STD_CMD_A(CmdPartPrimitives);
00196
00197 CmdPartPrimitives::CmdPartPrimitives()
00198 :Command("Part_Primitives")
00199 {
00200 sAppModule = "Part";
00201 sGroup = QT_TR_NOOP("Part");
00202 sMenuText = QT_TR_NOOP("Create primitives...");
00203 sToolTipText = QT_TR_NOOP("Creation of parametrized geometric primitives");
00204 sWhatsThis = "Part_Primitives";
00205 sStatusTip = sToolTipText;
00206 sPixmap = "Part_CreatePrimitives";
00207 }
00208
00209 void CmdPartPrimitives::activated(int iMsg)
00210 {
00211 static QPointer<QDialog> dlg = 0;
00212 if (!dlg)
00213 dlg = new PartGui::DlgPrimitives(Gui::getMainWindow());
00214 dlg->setAttribute(Qt::WA_DeleteOnClose);
00215 dlg->show();
00216 }
00217
00218 bool CmdPartPrimitives::isActive(void)
00219 {
00220 return hasActiveDocument();
00221 }
00222
00223
00224
00225
00226 DEF_STD_CMD_A(CmdPartCut);
00227
00228 CmdPartCut::CmdPartCut()
00229 :Command("Part_Cut")
00230 {
00231 sAppModule = "Part";
00232 sGroup = QT_TR_NOOP("Part");
00233 sMenuText = QT_TR_NOOP("Cut");
00234 sToolTipText = QT_TR_NOOP("Make a cut of two shapes");
00235 sWhatsThis = "Part_Cut";
00236 sStatusTip = sToolTipText;
00237 sPixmap = "Part_Cut";
00238 }
00239
00240 void CmdPartCut::activated(int iMsg)
00241 {
00242 unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId());
00243 if (n != 2) {
00244 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00245 QObject::tr("Select two shapes please."));
00246 return;
00247 }
00248
00249 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00250
00251 std::string FeatName = getUniqueObjectName("Cut");
00252 std::string BaseName = Sel[0].FeatName;
00253 std::string ToolName = Sel[1].FeatName;
00254
00255 openCommand("Part Cut");
00256 doCommand(Doc,"App.activeDocument().addObject(\"Part::Cut\",\"%s\")",FeatName.c_str());
00257 doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str());
00258 doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),ToolName.c_str());
00259 doCommand(Gui,"Gui.activeDocument().hide('%s')",BaseName.c_str());
00260 doCommand(Gui,"Gui.activeDocument().hide('%s')",ToolName.c_str());
00261 doCommand(Gui,"Gui.activeDocument().%s.ShapeColor = Gui.activeDocument().%s.ShapeColor", FeatName.c_str(),BaseName.c_str());
00262 updateActive();
00263 commitCommand();
00264 }
00265
00266 bool CmdPartCut::isActive(void)
00267 {
00268 return getSelection().countObjectsOfType(Part::Feature::getClassTypeId())==2;
00269 }
00270
00271
00272
00273
00274 DEF_STD_CMD_A(CmdPartCommon);
00275
00276 CmdPartCommon::CmdPartCommon()
00277 :Command("Part_Common")
00278 {
00279 sAppModule = "Part";
00280 sGroup = QT_TR_NOOP("Part");
00281 sMenuText = QT_TR_NOOP("Intersection");
00282 sToolTipText = QT_TR_NOOP("Make an intersection of two shapes");
00283 sWhatsThis = "Part_Common";
00284 sStatusTip = sToolTipText;
00285 sPixmap = "Part_Common";
00286 }
00287
00288 void CmdPartCommon::activated(int iMsg)
00289 {
00290 unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId());
00291 if (n < 2) {
00292 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00293 QObject::tr("Select two shapes or more, please."));
00294 return;
00295 }
00296
00297 std::string FeatName = getUniqueObjectName("Common");
00298
00299 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00300 std::string ObjectBuf;
00301 std::vector<std::string> tempSelNames;
00302 for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = Sel.begin(); it != Sel.end(); ++it){
00303 ObjectBuf += std::string("App.activeDocument().") + it->FeatName + ",";
00304 tempSelNames.push_back(it->FeatName);
00305 }
00306 ObjectBuf.erase(--ObjectBuf.end());
00307
00308 openCommand("Common");
00309 doCommand(Doc,"App.activeDocument().addObject(\"Part::MultiCommon\",\"%s\")",FeatName.c_str());
00310 doCommand(Doc,"App.activeDocument().%s.Shapes = [%s]",FeatName.c_str(),ObjectBuf.c_str());
00311 for (std::vector<std::string>::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it)
00312 doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str());
00313 doCommand(Gui,"Gui.activeDocument().%s.ShapeColor = Gui.activeDocument().%s.ShapeColor", FeatName.c_str(),tempSelNames.front().c_str());
00314 updateActive();
00315 commitCommand();
00316 }
00317
00318 bool CmdPartCommon::isActive(void)
00319 {
00320 return getSelection().countObjectsOfType(Part::Feature::getClassTypeId())>=2;
00321 }
00322
00323
00324
00325
00326 DEF_STD_CMD_A(CmdPartFuse);
00327
00328 CmdPartFuse::CmdPartFuse()
00329 :Command("Part_Fuse")
00330 {
00331 sAppModule = "Part";
00332 sGroup = QT_TR_NOOP("Part");
00333 sMenuText = QT_TR_NOOP("Union");
00334 sToolTipText = QT_TR_NOOP("Make a union of several shapes");
00335 sWhatsThis = "Part_Fuse";
00336 sStatusTip = sToolTipText;
00337 sPixmap = "Part_Fuse";
00338 }
00339
00340 void CmdPartFuse::activated(int iMsg)
00341 {
00342 unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId());
00343 if (n < 2) {
00344 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00345 QObject::tr("Select two shapes or more, please."));
00346 return;
00347 }
00348
00349 std::string FeatName = getUniqueObjectName("Fusion");
00350
00351 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00352 std::string ObjectBuf;
00353 std::vector<std::string> tempSelNames;
00354 for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = Sel.begin(); it != Sel.end(); ++it){
00355 ObjectBuf += std::string("App.activeDocument().") + it->FeatName + ",";
00356 tempSelNames.push_back(it->FeatName);
00357 }
00358 ObjectBuf.erase(--ObjectBuf.end());
00359
00360 openCommand("Fusion");
00361 doCommand(Doc,"App.activeDocument().addObject(\"Part::MultiFuse\",\"%s\")",FeatName.c_str());
00362 doCommand(Doc,"App.activeDocument().%s.Shapes = [%s]",FeatName.c_str(),ObjectBuf.c_str());
00363 for (std::vector<std::string>::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it)
00364 doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str());
00365 doCommand(Gui,"Gui.activeDocument().%s.ShapeColor = Gui.activeDocument().%s.ShapeColor", FeatName.c_str(),tempSelNames.front().c_str());
00366 updateActive();
00367 commitCommand();
00368 }
00369
00370 bool CmdPartFuse::isActive(void)
00371 {
00372 return getSelection().countObjectsOfType(Part::Feature::getClassTypeId())>=2;
00373 }
00374
00375
00376
00377
00378 DEF_STD_CMD_A(CmdPartSection);
00379
00380 CmdPartSection::CmdPartSection()
00381 :Command("Part_Section")
00382 {
00383 sAppModule = "Part";
00384 sGroup = QT_TR_NOOP("Part");
00385 sMenuText = QT_TR_NOOP("Section");
00386 sToolTipText = QT_TR_NOOP("Make a section of two shapes");
00387 sWhatsThis = "Part_Section";
00388 sStatusTip = sToolTipText;
00389 sPixmap = "Part_Section";
00390 }
00391
00392
00393 void CmdPartSection::activated(int iMsg)
00394 {
00395 unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId());
00396 if (n != 2) {
00397 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00398 QObject::tr("Select two shapes please."));
00399 return;
00400 }
00401
00402 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00403 std::string FeatName = getUniqueObjectName("Section");
00404 std::string BaseName = Sel[0].FeatName;
00405 std::string ToolName = Sel[1].FeatName;
00406
00407 openCommand("Section");
00408 doCommand(Doc,"App.activeDocument().addObject(\"Part::Section\",\"%s\")",FeatName.c_str());
00409 doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str());
00410 doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),ToolName.c_str());
00411 doCommand(Gui,"Gui.activeDocument().hide('%s')",BaseName.c_str());
00412 doCommand(Gui,"Gui.activeDocument().hide('%s')",ToolName.c_str());
00413 doCommand(Gui,"Gui.activeDocument().%s.LineColor = Gui.activeDocument().%s.ShapeColor", FeatName.c_str(),BaseName.c_str());
00414 updateActive();
00415 commitCommand();
00416 }
00417
00418 bool CmdPartSection::isActive(void)
00419 {
00420 return getSelection().countObjectsOfType(Part::Feature::getClassTypeId())==2;
00421 }
00422
00423
00424
00425
00426 DEF_STD_CMD_A(CmdPartImport);
00427
00428 CmdPartImport::CmdPartImport()
00429 :Command("Part_Import")
00430 {
00431 sAppModule = "Part";
00432 sGroup = QT_TR_NOOP("Part");
00433 sMenuText = QT_TR_NOOP("Import CAD...");
00434 sToolTipText = QT_TR_NOOP("Imports a CAD file");
00435 sWhatsThis = "Part_Import";
00436 sStatusTip = sToolTipText;
00437 sPixmap = "Part_Import";
00438 }
00439
00440
00441 void CmdPartImport::activated(int iMsg)
00442 {
00443 QStringList filter;
00444 filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)");
00445 filter << QObject::tr("STEP (*.stp *.step)");
00446 filter << QObject::tr("IGES (*.igs *.iges)");
00447 filter << QObject::tr("BREP (*.brp *.brep)");
00448 filter << QObject::tr("All Files (*.*)");
00449
00450 QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;")));
00451 if (!fn.isEmpty()) {
00452 App::Document* pDoc = getDocument();
00453 if (!pDoc) return;
00454 openCommand("Import Part");
00455 QString ext = QFileInfo(fn).suffix().toLower();
00456 if (ext == QLatin1String("step") ||
00457 ext == QLatin1String("stp") ||
00458 ext == QLatin1String("iges") ||
00459 ext == QLatin1String("igs")) {
00460 doCommand(Doc, "import ImportGui");
00461 doCommand(Doc, "ImportGui.insert(\"%s\",\"%s\")", (const char*)fn.toUtf8(), pDoc->getName());
00462 }
00463 else {
00464 doCommand(Doc, "import Part");
00465 doCommand(Doc, "Part.insert(\"%s\",\"%s\")", (const char*)fn.toUtf8(), pDoc->getName());
00466 }
00467 commitCommand();
00468 }
00469 }
00470
00471 bool CmdPartImport::isActive(void)
00472 {
00473 if (getActiveGuiDocument())
00474 return true;
00475 else
00476 return false;
00477 }
00478
00479
00480
00481
00482 DEF_STD_CMD_A(CmdPartExport);
00483
00484 CmdPartExport::CmdPartExport()
00485 : Command("Part_Export")
00486 {
00487 sAppModule = "Part";
00488 sGroup = QT_TR_NOOP("Part");
00489 sMenuText = QT_TR_NOOP("Export CAD...");
00490 sToolTipText = QT_TR_NOOP("Exports to a CAD file");
00491 sWhatsThis = "Part_Export";
00492 sStatusTip = sToolTipText;
00493
00494 }
00495
00496 void CmdPartExport::activated(int iMsg)
00497 {
00498 QStringList filter;
00499 filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)");
00500 filter << QObject::tr("STEP (*.stp *.step)");
00501 filter << QObject::tr("IGES (*.igs *.iges)");
00502 filter << QObject::tr("BREP (*.brp *.brep)");
00503 filter << QObject::tr("All Files (*.*)");
00504
00505 QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;")));
00506 if (!fn.isEmpty()) {
00507 App::Document* pDoc = getDocument();
00508 if (!pDoc) return;
00509 openCommand("Import Part");
00510 QString ext = QFileInfo(fn).suffix().toLower();
00511 if (ext == QLatin1String("step") ||
00512 ext == QLatin1String("stp") ||
00513 ext == QLatin1String("iges") ||
00514 ext == QLatin1String("igs")) {
00515 Gui::Application::Instance->exportTo((const char*)fn.toUtf8(),pDoc->getName(),"ImportGui");
00516 }
00517 else {
00518 Gui::Application::Instance->exportTo((const char*)fn.toUtf8(),pDoc->getName(),"Part");
00519 }
00520 commitCommand();
00521 }
00522 }
00523
00524 bool CmdPartExport::isActive(void)
00525 {
00526 return Gui::Selection().countObjectsOfType(Part::Feature::getClassTypeId()) > 0;
00527 }
00528
00529
00530
00531
00532 DEF_STD_CMD_A(CmdPartImportCurveNet);
00533
00534 CmdPartImportCurveNet::CmdPartImportCurveNet()
00535 :Command("Part_ImportCurveNet")
00536 {
00537 sAppModule = "Part";
00538 sGroup = QT_TR_NOOP("Part");
00539 sMenuText = QT_TR_NOOP("Import curve network...");
00540 sToolTipText= QT_TR_NOOP("Import a curve network");
00541 sWhatsThis = "Part_ImportCurveNet";
00542 sStatusTip = sToolTipText;
00543 sPixmap = "Part_Box";
00544 }
00545
00546 void CmdPartImportCurveNet::activated(int iMsg)
00547 {
00548 QStringList filter;
00549 filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)");
00550 filter << QObject::tr("STEP (*.stp *.step)");
00551 filter << QObject::tr("IGES (*.igs *.iges)");
00552 filter << QObject::tr("BREP (*.brp *.brep)");
00553 filter << QObject::tr("All Files (*.*)");
00554
00555 QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;")));
00556 if (!fn.isEmpty()) {
00557 QFileInfo fi; fi.setFile(fn);
00558 openCommand("Part Import Curve Net");
00559 doCommand(Doc,"f = App.activeDocument().addObject(\"Part::CurveNet\",\"%s\")", (const char*)fi.baseName().toAscii());
00560 doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii());
00561 commitCommand();
00562 updateActive();
00563 }
00564 }
00565
00566 bool CmdPartImportCurveNet::isActive(void)
00567 {
00568 if (getActiveGuiDocument())
00569 return true;
00570 else
00571 return false;
00572 }
00573
00574
00575
00576
00577 DEF_STD_CMD_A(CmdPartMakeSolid);
00578
00579 CmdPartMakeSolid::CmdPartMakeSolid()
00580 :Command("Part_MakeSolid")
00581 {
00582 sAppModule = "Part";
00583 sGroup = QT_TR_NOOP("Part");
00584 sMenuText = QT_TR_NOOP("Convert to solid");
00585 sToolTipText = QT_TR_NOOP("Create solid from a shell or compound");
00586 sWhatsThis = "Part_MakeSolid";
00587 sStatusTip = sToolTipText;
00588 }
00589
00590 void CmdPartMakeSolid::activated(int iMsg)
00591 {
00592 std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType
00593 (Part::Feature::getClassTypeId());
00594 doCommand(Doc, "import Part");
00595 for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
00596 const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
00597 if (!shape.IsNull()) {
00598 TopAbs_ShapeEnum type = shape.ShapeType();
00599 QString str;
00600 if (type == TopAbs_SOLID) {
00601 Base::Console().Message("%s is ignored because it is already a solid.\n",
00602 (*it)->Label.getValue());
00603 }
00604 else if (type == TopAbs_COMPOUND || type == TopAbs_COMPSOLID) {
00605 str = QString::fromAscii(
00606 "__s__=App.ActiveDocument.%1.Shape.Faces\n"
00607 "__s__=Part.Solid(Part.Shell(__s__))\n"
00608 "__o__=App.ActiveDocument.addObject(\"Part::Feature\",\"%1_solid\")\n"
00609 "__o__.Label=\"%2 (Solid)\"\n"
00610 "__o__.Shape=__s__\n"
00611 "del __s__, __o__"
00612 )
00613 .arg(QLatin1String((*it)->getNameInDocument()))
00614 .arg(QLatin1String((*it)->Label.getValue()));
00615 }
00616 else if (type == TopAbs_SHELL) {
00617 str = QString::fromAscii(
00618 "__s__=App.ActiveDocument.%1.Shape\n"
00619 "__s__=Part.Solid(__s__)\n"
00620 "__o__=App.ActiveDocument.addObject(\"Part::Feature\",\"%1_solid\")\n"
00621 "__o__.Label=\"%2 (Solid)\"\n"
00622 "__o__.Shape=__s__\n"
00623 "del __s__, __o__"
00624 )
00625 .arg(QLatin1String((*it)->getNameInDocument()))
00626 .arg(QLatin1String((*it)->Label.getValue()));
00627 }
00628 else {
00629 Base::Console().Message("%s is ignored because it is neither a shell nor a compound.\n",
00630 (*it)->Label.getValue());
00631 }
00632
00633 try {
00634 if (!str.isEmpty())
00635 doCommand(Doc, (const char*)str.toAscii());
00636 }
00637 catch (const Base::Exception& e) {
00638 Base::Console().Error("Cannot convert %s because %s.\n",
00639 (*it)->Label.getValue(), e.what());
00640 }
00641 }
00642 }
00643 }
00644
00645 bool CmdPartMakeSolid::isActive(void)
00646 {
00647 return Gui::Selection().countObjectsOfType
00648 (Part::Feature::getClassTypeId()) > 0;
00649 }
00650
00651
00652
00653
00654 DEF_STD_CMD_A(CmdPartReverseShape);
00655
00656 CmdPartReverseShape::CmdPartReverseShape()
00657 :Command("Part_ReverseShape")
00658 {
00659 sAppModule = "Part";
00660 sGroup = QT_TR_NOOP("Part");
00661 sMenuText = QT_TR_NOOP("Reverse shapes");
00662 sToolTipText = QT_TR_NOOP("Reverse orientation of shapes");
00663 sWhatsThis = "Part_ReverseShape";
00664 sStatusTip = sToolTipText;
00665 }
00666
00667 void CmdPartReverseShape::activated(int iMsg)
00668 {
00669 std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType
00670 (Part::Feature::getClassTypeId());
00671 doCommand(Doc, "import Part");
00672 for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
00673 const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
00674 if (!shape.IsNull()) {
00675 QString str = QString::fromAscii(
00676 "__s__=App.ActiveDocument.%1.Shape.copy()\n"
00677 "__s__.reverse()\n"
00678 "__o__=App.ActiveDocument.addObject(\"Part::Feature\",\"%1_rev\")\n"
00679 "__o__.Label=\"%2 (Rev)\"\n"
00680 "__o__.Shape=__s__\n"
00681 "del __s__, __o__"
00682 )
00683 .arg(QLatin1String((*it)->getNameInDocument()))
00684 .arg(QLatin1String((*it)->Label.getValue()));
00685
00686 try {
00687 if (!str.isEmpty())
00688 doCommand(Doc, (const char*)str.toAscii());
00689 }
00690 catch (const Base::Exception& e) {
00691 Base::Console().Error("Cannot convert %s because %s.\n",
00692 (*it)->Label.getValue(), e.what());
00693 }
00694 }
00695 }
00696 }
00697
00698 bool CmdPartReverseShape::isActive(void)
00699 {
00700 return Gui::Selection().countObjectsOfType
00701 (Part::Feature::getClassTypeId()) > 0;
00702 }
00703
00704
00705
00706
00707 DEF_STD_CMD_A(CmdPartBoolean);
00708
00709 CmdPartBoolean::CmdPartBoolean()
00710 :Command("Part_Boolean")
00711 {
00712 sAppModule = "Part";
00713 sGroup = QT_TR_NOOP("Part");
00714 sMenuText = QT_TR_NOOP("Boolean...");
00715 sToolTipText = QT_TR_NOOP("Run a boolean operation with two shapes selected");
00716 sWhatsThis = "Part_Boolean";
00717 sStatusTip = sToolTipText;
00718 sPixmap = "Part_Booleans";
00719 }
00720
00721 void CmdPartBoolean::activated(int iMsg)
00722 {
00723 Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
00724 if (!dlg)
00725 dlg = new PartGui::TaskBooleanOperation();
00726 Gui::Control().showDialog(dlg);
00727 }
00728
00729 bool CmdPartBoolean::isActive(void)
00730 {
00731 return (hasActiveDocument() && !Gui::Control().activeDialog());
00732 }
00733
00734
00735
00736
00737 DEF_STD_CMD_A(CmdPartExtrude);
00738
00739 CmdPartExtrude::CmdPartExtrude()
00740 :Command("Part_Extrude")
00741 {
00742 sAppModule = "Part";
00743 sGroup = QT_TR_NOOP("Part");
00744 sMenuText = QT_TR_NOOP("Extrude...");
00745 sToolTipText = QT_TR_NOOP("Extrude a selected sketch");
00746 sWhatsThis = sToolTipText;
00747 sStatusTip = sToolTipText;
00748 sPixmap = "Part_Extrude";
00749 }
00750
00751 void CmdPartExtrude::activated(int iMsg)
00752 {
00753 Gui::Control().showDialog(new PartGui::TaskExtrusion());
00754 }
00755
00756 bool CmdPartExtrude::isActive(void)
00757 {
00758 return (hasActiveDocument() && !Gui::Control().activeDialog());
00759 }
00760
00761
00762
00763
00764 DEF_STD_CMD_A(CmdPartRevolve);
00765
00766 CmdPartRevolve::CmdPartRevolve()
00767 :Command("Part_Revolve")
00768 {
00769 sAppModule = "Part";
00770 sGroup = QT_TR_NOOP("Part");
00771 sMenuText = QT_TR_NOOP("Revolve...");
00772 sToolTipText = QT_TR_NOOP("Revolve a selected shape");
00773 sWhatsThis = sToolTipText;
00774 sStatusTip = sToolTipText;
00775 sPixmap = "Part_Revolve";
00776 }
00777
00778 void CmdPartRevolve::activated(int iMsg)
00779 {
00780 Gui::Control().showDialog(new PartGui::TaskRevolution());
00781 }
00782
00783 bool CmdPartRevolve::isActive(void)
00784 {
00785 return (hasActiveDocument() && !Gui::Control().activeDialog());
00786 }
00787
00788
00789
00790
00791 DEF_STD_CMD_A(CmdPartFillet);
00792
00793 CmdPartFillet::CmdPartFillet()
00794 :Command("Part_Fillet")
00795 {
00796 sAppModule = "Part";
00797 sGroup = QT_TR_NOOP("Part");
00798 sMenuText = QT_TR_NOOP("Fillet...");
00799 sToolTipText = QT_TR_NOOP("Fillet the selected edges of a shape");
00800 sWhatsThis = sToolTipText;
00801 sStatusTip = sToolTipText;
00802 sPixmap = "Part_Fillet";
00803 }
00804
00805 void CmdPartFillet::activated(int iMsg)
00806 {
00807 Gui::Control().showDialog(new PartGui::TaskFilletEdges(0));
00808 }
00809
00810 bool CmdPartFillet::isActive(void)
00811 {
00812 return (hasActiveDocument() && !Gui::Control().activeDialog());
00813 }
00814
00815
00816
00817
00818 DEF_STD_CMD_A(CmdPartMirror);
00819
00820 CmdPartMirror::CmdPartMirror()
00821 :Command("Part_Mirror")
00822 {
00823 sAppModule = "Part";
00824 sGroup = QT_TR_NOOP("Part");
00825 sMenuText = QT_TR_NOOP("Mirroring...");
00826 sToolTipText = QT_TR_NOOP("Mirroring a selected shape");
00827 sWhatsThis = sToolTipText;
00828 sStatusTip = sToolTipText;
00829 sPixmap = "Part_MirrorPNG";
00830 }
00831
00832 void CmdPartMirror::activated(int iMsg)
00833 {
00834 Gui::Control().showDialog(new PartGui::TaskMirroring());
00835 }
00836
00837 bool CmdPartMirror::isActive(void)
00838 {
00839 return (hasActiveDocument() && !Gui::Control().activeDialog());
00840 }
00841
00842
00843
00844
00845 DEF_STD_CMD_A(CmdPartCrossSections);
00846
00847 CmdPartCrossSections::CmdPartCrossSections()
00848 :Command("Part_CrossSections")
00849 {
00850 sAppModule = "Part";
00851 sGroup = QT_TR_NOOP("Part");
00852 sMenuText = QT_TR_NOOP("Cross-sections...");
00853 sToolTipText = QT_TR_NOOP("Cross-sections");
00854 sWhatsThis = "Part_CrossSections";
00855 sStatusTip = sToolTipText;
00856
00857 }
00858
00859 void CmdPartCrossSections::activated(int iMsg)
00860 {
00861 Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
00862 if (!dlg) {
00863 std::vector<App::DocumentObject*> obj = Gui::Selection().getObjectsOfType
00864 (Part::Feature::getClassTypeId());
00865 Base::BoundBox3d bbox;
00866 for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
00867 bbox.Add(static_cast<Part::Feature*>(*it)->Shape.getBoundingBox());
00868 }
00869 dlg = new PartGui::TaskCrossSections(bbox);
00870 }
00871 Gui::Control().showDialog(dlg);
00872 }
00873
00874 bool CmdPartCrossSections::isActive(void)
00875 {
00876 return (Gui::Selection().countObjectsOfType(Part::Feature::getClassTypeId()) > 0 &&
00877 !Gui::Control().activeDialog());
00878 }
00879
00880
00881
00882 DEF_STD_CMD_A(CmdPartBuilder);
00883
00884 CmdPartBuilder::CmdPartBuilder()
00885 :Command("Part_Builder")
00886 {
00887 sAppModule = "Part";
00888 sGroup = QT_TR_NOOP("Part");
00889 sMenuText = QT_TR_NOOP("Shape builder...");
00890 sToolTipText = QT_TR_NOOP("Advanced utility to create shapes");
00891 sWhatsThis = sToolTipText;
00892 sStatusTip = sToolTipText;
00893 sPixmap = "Part_Shapebuilder";
00894 }
00895
00896 void CmdPartBuilder::activated(int iMsg)
00897 {
00898 Gui::Control().showDialog(new PartGui::TaskShapeBuilder());
00899 }
00900
00901 bool CmdPartBuilder::isActive(void)
00902 {
00903 return (hasActiveDocument() && !Gui::Control().activeDialog());
00904 }
00905
00906
00907
00908 DEF_STD_CMD_A(CmdPartLoft);
00909
00910 CmdPartLoft::CmdPartLoft()
00911 : Command("Part_Loft")
00912 {
00913 sAppModule = "Part";
00914 sGroup = QT_TR_NOOP("Part");
00915 sMenuText = QT_TR_NOOP("Loft...");
00916 sToolTipText = QT_TR_NOOP("Advanced utility to lofts");
00917 sWhatsThis = sToolTipText;
00918 sStatusTip = sToolTipText;
00919 }
00920
00921 void CmdPartLoft::activated(int iMsg)
00922 {
00923 Gui::Control().showDialog(new PartGui::TaskLoft());
00924 }
00925
00926 bool CmdPartLoft::isActive(void)
00927 {
00928 return (hasActiveDocument() && !Gui::Control().activeDialog());
00929 }
00930
00931
00932
00933 DEF_STD_CMD_A(CmdShapeInfo);
00934
00935 CmdShapeInfo::CmdShapeInfo()
00936 :Command("Part_ShapeInfo")
00937 {
00938 sAppModule = "Part";
00939 sGroup = "Part";
00940 sMenuText = "Shape info...";
00941 sToolTipText = "Info about shape";
00942 sWhatsThis = sToolTipText;
00943 sStatusTip = sToolTipText;
00944 sPixmap = "Part_ShapeInfo";
00945 }
00946
00947 void CmdShapeInfo::activated(int iMsg)
00948 {
00949 static const char * const part_pipette[]={
00950 "32 32 17 1",
00951 "# c #000000",
00952 "j c #080808",
00953 "b c #101010",
00954 "f c #1c1c1c",
00955 "g c #4c4c4c",
00956 "c c #777777",
00957 "a c #848484",
00958 "i c #9c9c9c",
00959 "l c #b9b9b9",
00960 "e c #cacaca",
00961 "n c #d6d6d6",
00962 "k c #dedede",
00963 "d c #e7e7e7",
00964 "m c #efefef",
00965 "h c #f7f7f7",
00966 "w c #ffffff",
00967 ". c None",
00968 "................................",
00969 ".....................#####......",
00970 "...................#######......",
00971 "...................#########....",
00972 "..................##########....",
00973 "..................##########....",
00974 "..................##########....",
00975 ".................###########....",
00976 "...............#############....",
00977 ".............###############....",
00978 ".............#############......",
00979 ".............#############......",
00980 "...............ab######.........",
00981 "..............cdef#####.........",
00982 ".............ghdacf####.........",
00983 "............#ehiacj####.........",
00984 "............awiaaf####..........",
00985 "...........iheacf##.............",
00986 "..........#kdaag##..............",
00987 ".........gedaacb#...............",
00988 ".........lwiac##................",
00989 ".......#amlaaf##................",
00990 ".......cheaag#..................",
00991 "......#ndaag##..................",
00992 ".....#imaacb#...................",
00993 ".....iwlacf#....................",
00994 "....#nlaag##....................",
00995 "....feaagj#.....................",
00996 "....caag##......................",
00997 "....ffbj##......................",
00998 "................................",
00999 "................................"};
01000
01001 Gui::Document* doc = Gui::Application::Instance->activeDocument();
01002 Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
01003
01004
01005
01006
01007
01008
01009 }
01010
01011 bool CmdShapeInfo::isActive(void)
01012 {
01013 App::Document* doc = App::GetApplication().getActiveDocument();
01014 if (!doc || doc->countObjectsOfType(Part::Feature::getClassTypeId()) == 0)
01015 return false;
01016
01017 Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
01018 if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
01019 Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
01020 return !viewer->isEditing();
01021 }
01022
01023 return false;
01024 }
01025
01026 DEF_STD_CMD_A(CmdPartRuledSurface);
01027
01028 CmdPartRuledSurface::CmdPartRuledSurface()
01029 : Command("Part_RuledSurface")
01030 {
01031 sAppModule = "Part";
01032 sGroup = QT_TR_NOOP("Part");
01033 sMenuText = QT_TR_NOOP("Create ruled surface");
01034 sToolTipText = QT_TR_NOOP("Create a ruled surface from two curves");
01035 sWhatsThis = sToolTipText;
01036 sStatusTip = sToolTipText;
01037 sPixmap = "Part_RuledSurface";
01038 }
01039
01040 void CmdPartRuledSurface::activated(int iMsg)
01041 {
01042 bool ok = false;
01043 TopoDS_Shape curve1, curve2;
01044 std::string link1, link2, obj1, obj2;
01045 Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1..2");
01046 Gui::SelectionFilter wireFilter ("SELECT Part::Feature SUBELEMENT Wire COUNT 1..2");
01047 Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 2");
01048 bool matchEdge = edgeFilter.match();
01049 bool matchWire = wireFilter.match();
01050 if (matchEdge || matchWire) {
01051
01052 const std::vector<Gui::SelectionObject>& result = matchEdge
01053 ? edgeFilter.Result[0] : wireFilter.Result[0];
01054
01055 if (result.size() == 1) {
01056 const Part::Feature* part = static_cast<const Part::Feature*>(result[0].getObject());
01057 const std::vector<std::string>& edges = result[0].getSubNames();
01058 if (edges.size() != 2) {
01059 ok = false;
01060 }
01061 else {
01062 ok = true;
01063
01064 const Part::TopoShape& shape = part->Shape.getValue();
01065 curve1 = shape.getSubShape(edges[0].c_str());
01066 curve2 = shape.getSubShape(edges[1].c_str());
01067 obj1 = result[0].getObject()->getNameInDocument();
01068 link1 = edges[0];
01069 obj2 = result[0].getObject()->getNameInDocument();
01070 link2 = edges[1];
01071 }
01072 }
01073
01074 else if (result.size() == 2) {
01075 const Part::Feature* part1 = static_cast<const Part::Feature*>(result[0].getObject());
01076 const std::vector<std::string>& edges1 = result[0].getSubNames();
01077 const Part::Feature* part2 = static_cast<const Part::Feature*>(result[1].getObject());
01078 const std::vector<std::string>& edges2 = result[1].getSubNames();
01079 if (edges1.size() != 1 || edges2.size() != 1) {
01080 ok = false;
01081 }
01082 else {
01083 ok = true;
01084 const Part::TopoShape& shape1 = part1->Shape.getValue();
01085 curve1 = shape1.getSubShape(edges1[0].c_str());
01086 const Part::TopoShape& shape2 = part2->Shape.getValue();
01087 curve2 = shape2.getSubShape(edges2[0].c_str());
01088 obj1 = result[0].getObject()->getNameInDocument();
01089 link1 = edges1[0];
01090 obj2 = result[1].getObject()->getNameInDocument();
01091 link2 = edges2[0];
01092 }
01093 }
01094 }
01095 else if (partFilter.match()) {
01096 const std::vector<Gui::SelectionObject>& result = partFilter.Result[0];
01097 const Part::Feature* part1 = static_cast<const Part::Feature*>(result[0].getObject());
01098 const Part::Feature* part2 = static_cast<const Part::Feature*>(result[1].getObject());
01099 const Part::TopoShape& shape1 = part1->Shape.getValue();
01100 curve1 = shape1._Shape;
01101 const Part::TopoShape& shape2 = part2->Shape.getValue();
01102 curve2 = shape2._Shape;
01103 obj1 = part1->getNameInDocument();
01104 obj2 = part2->getNameInDocument();
01105
01106 if (!curve1.IsNull() && !curve2.IsNull()) {
01107 if (curve1.ShapeType() == TopAbs_EDGE &&
01108 curve2.ShapeType() == TopAbs_EDGE)
01109 ok = true;
01110 if (curve1.ShapeType() == TopAbs_WIRE &&
01111 curve2.ShapeType() == TopAbs_WIRE)
01112 ok = true;
01113 }
01114 }
01115
01116 if (!ok) {
01117 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
01118 QObject::tr("You have to select either two edges or two wires."));
01119 return;
01120 }
01121
01122 openCommand("Create ruled surface");
01123 doCommand(Doc, "FreeCAD.ActiveDocument.addObject('Part::RuledSurface','Filled shape')");
01124 doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.Curve1=(FreeCAD.ActiveDocument.%s,['%s'])"
01125 ,obj1.c_str(), link1.c_str());
01126 doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.Curve2=(FreeCAD.ActiveDocument.%s,['%s'])"
01127 ,obj2.c_str(), link2.c_str());
01128 commitCommand();
01129 updateActive();
01130 }
01131
01132 bool CmdPartRuledSurface::isActive(void)
01133 {
01134 return getActiveGuiDocument();
01135 }
01136
01137
01138 void CreatePartCommands(void)
01139 {
01140 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
01141
01142 rcCmdMgr.addCommand(new CmdPartMakeSolid());
01143 rcCmdMgr.addCommand(new CmdPartReverseShape());
01144 rcCmdMgr.addCommand(new CmdPartBoolean());
01145 rcCmdMgr.addCommand(new CmdPartExtrude());
01146 rcCmdMgr.addCommand(new CmdPartMirror());
01147 rcCmdMgr.addCommand(new CmdPartRevolve());
01148 rcCmdMgr.addCommand(new CmdPartCrossSections());
01149 rcCmdMgr.addCommand(new CmdPartFillet());
01150 rcCmdMgr.addCommand(new CmdPartCommon());
01151 rcCmdMgr.addCommand(new CmdPartCut());
01152 rcCmdMgr.addCommand(new CmdPartFuse());
01153 rcCmdMgr.addCommand(new CmdPartSection());
01154
01155
01156 rcCmdMgr.addCommand(new CmdPartPrimitives());
01157
01158 rcCmdMgr.addCommand(new CmdPartImport());
01159 rcCmdMgr.addCommand(new CmdPartExport());
01160 rcCmdMgr.addCommand(new CmdPartImportCurveNet());
01161 rcCmdMgr.addCommand(new CmdPartPickCurveNet());
01162 rcCmdMgr.addCommand(new CmdShapeInfo());
01163 rcCmdMgr.addCommand(new CmdPartRuledSurface());
01164 rcCmdMgr.addCommand(new CmdPartBuilder());
01165 rcCmdMgr.addCommand(new CmdPartLoft());
01166 }
01167