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>
14 #include <XGUI_OperationMgr.h>
16 #include <GeomAPI_Face.h>
18 #include <ModelAPI_Session.h>
19 #include <ModelAPI_ResultBody.h>
21 #include <ModuleBase_Tools.h>
22 #include <ModuleBase_Operation.h>
23 #include <ModuleBase_IPropertyPanel.h>
24 #include <Config_WidgetAPI.h>
28 #include <QFormLayout>
29 #include <QMessageBox>
31 PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
32 PartSet_Module* theModule,
33 const Config_WidgetAPI* theData,
34 const std::string& theParentId)
35 : ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule)
37 QFormLayout* aLayout = new QFormLayout(this);
38 ModuleBase_Tools::adjustMargins(aLayout);
40 QString aLabelText = QString::fromStdString(theData->widgetLabel());
41 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
42 myLabel = new QLabel(aLabelText, this);
43 if (!aLabelIcon.isEmpty())
44 myLabel->setPixmap(QPixmap(aLabelIcon));
47 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
48 myTextLine = new QLineEdit(this);
49 myTextLine->setReadOnly(true);
50 myTextLine->setToolTip(aToolTip);
51 myTextLine->installEventFilter(this);
53 aLayout->addRow(myLabel, myTextLine);
56 PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator()
60 QList<QWidget*> PartSet_WidgetSketchCreator::getControls() const
62 QList<QWidget*> aControls;
63 aControls.append(myTextLine);
67 bool PartSet_WidgetSketchCreator::restoreValue()
69 CompositeFeaturePtr aCompFeature =
70 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
71 if (aCompFeature->numberOfSubs() > 0) {
72 FeaturePtr aSubFeature = aCompFeature->subFeature(0);
73 myTextLine->setText(QString::fromStdString(aSubFeature->data()->name()));
78 bool PartSet_WidgetSketchCreator::storeValueCustom() const
83 void PartSet_WidgetSketchCreator::activateCustom()
85 CompositeFeaturePtr aCompFeature =
86 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
87 if (aCompFeature->numberOfSubs() == 0)
88 connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
91 void PartSet_WidgetSketchCreator::onStarted()
93 disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
95 // Check that model already has bodies
96 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
97 XGUI_Workshop* aWorkshop = aConnector->workshop();
98 XGUI_Displayer* aDisp = aWorkshop->displayer();
99 QObjectPtrList aObjList = aDisp->displayedObjects();
100 bool aHasBody = false;
102 foreach(ObjectPtr aObj, aObjList) {
103 aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
104 if (aBody.get() != NULL) {
111 // Launch Sketch operation
112 CompositeFeaturePtr aCompFeature =
113 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
114 FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
116 ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
117 anOperation->setFeature(aSketch);
118 myModule->sendOperation(anOperation);
119 //connect(anOperation, SIGNAL(aborted()), aWorkshop->operationMgr(), SLOT(abortAllOperations()));
121 // Break current operation
122 QMessageBox::warning(this, tr("Extrusion Cut"),
123 tr("There are no bodies found. Operation aborted."), QMessageBox::Ok);
124 ModuleBase_Operation* aOp = myModule->workshop()->currentOperation();
129 bool PartSet_WidgetSketchCreator::focusTo()
131 CompositeFeaturePtr aCompFeature =
132 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
133 if (aCompFeature->numberOfSubs() == 0)
134 return ModuleBase_ModelWidget::focusTo();
136 CompositeFeaturePtr aSketchFeature =
137 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aCompFeature->subFeature(0));
138 if (aSketchFeature->numberOfSubs() == 0) {
139 connect(myModule, SIGNAL(operationResumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*)));
141 SessionPtr aMgr = ModelAPI_Session::get();
142 bool aIsOp = aMgr->isOperation();
143 // Open transaction if it was closed before
145 aMgr->startOperation();
151 void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp)
154 SessionPtr aMgr = ModelAPI_Session::get();
155 bool aIsOp = aMgr->isOperation();
158 aMgr->abortOperation();