1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetSketchCreator.cpp
4 // Created: 08 June 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_WidgetSketchCreator.h"
8 #include "PartSet_Module.h"
10 #include <XGUI_ModuleConnector.h>
11 #include <XGUI_Workshop.h>
12 #include <XGUI_Displayer.h>
13 #include <XGUI_SelectionMgr.h>
15 #include <GeomAPI_Face.h>
17 #include <ModelAPI_Session.h>
18 #include <ModelAPI_ResultBody.h>
20 #include <ModuleBase_Tools.h>
21 #include <ModuleBase_Operation.h>
22 #include <ModuleBase_IPropertyPanel.h>
23 #include <Config_WidgetAPI.h>
27 #include <QFormLayout>
28 #include <QMessageBox>
30 PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
31 PartSet_Module* theModule,
32 const Config_WidgetAPI* theData,
33 const std::string& theParentId)
34 : ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule)
36 QFormLayout* aLayout = new QFormLayout(this);
37 ModuleBase_Tools::adjustMargins(aLayout);
39 QString aLabelText = QString::fromStdString(theData->widgetLabel());
40 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
41 myLabel = new QLabel(aLabelText, this);
42 if (!aLabelIcon.isEmpty())
43 myLabel->setPixmap(QPixmap(aLabelIcon));
46 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
47 myTextLine = new QLineEdit(this);
48 myTextLine->setReadOnly(true);
49 myTextLine->setToolTip(aToolTip);
50 myTextLine->installEventFilter(this);
52 aLayout->addRow(myLabel, myTextLine);
55 PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator()
59 QList<QWidget*> PartSet_WidgetSketchCreator::getControls() const
61 QList<QWidget*> aControls;
62 aControls.append(myTextLine);
66 bool PartSet_WidgetSketchCreator::restoreValue()
68 CompositeFeaturePtr aCompFeature =
69 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
70 if (aCompFeature->numberOfSubs() > 0) {
71 FeaturePtr aSubFeature = aCompFeature->subFeature(0);
72 myTextLine->setText(QString::fromStdString(aSubFeature->data()->name()));
77 bool PartSet_WidgetSketchCreator::storeValueCustom() const
82 void PartSet_WidgetSketchCreator::activateCustom()
84 CompositeFeaturePtr aCompFeature =
85 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
86 if (aCompFeature->numberOfSubs() == 0)
87 connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
90 void PartSet_WidgetSketchCreator::onStarted()
92 disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
94 // Check that model already has bodies
95 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
96 XGUI_Workshop* aWorkshop = aConnector->workshop();
97 XGUI_Displayer* aDisp = aWorkshop->displayer();
98 QObjectPtrList aObjList = aDisp->displayedObjects();
99 bool aHasBody = false;
101 foreach(ObjectPtr aObj, aObjList) {
102 aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
103 if (aBody.get() != NULL) {
110 // Launch Sketch operation
111 CompositeFeaturePtr aCompFeature =
112 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
113 FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
115 ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
116 anOperation->setFeature(aSketch);
117 myModule->sendOperation(anOperation);
119 // Break current operation
120 QMessageBox::warning(this, tr("Extrusion Cut"),
121 tr("There are no bodies found. Operation aborted."), QMessageBox::Ok);
122 ModuleBase_Operation* aOp = myModule->workshop()->currentOperation();
127 bool PartSet_WidgetSketchCreator::focusTo()
129 CompositeFeaturePtr aCompFeature =
130 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
131 if (aCompFeature->numberOfSubs() == 0)
132 return ModuleBase_ModelWidget::focusTo();
134 SessionPtr aMgr = ModelAPI_Session::get();
135 bool aIsOp = aMgr->isOperation();
136 // Open transaction if it was closed before
138 aMgr->startOperation();