1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_Module.h"
4 #include "PartSet_WidgetSketchLabel.h"
5 #include "PartSet_Validators.h"
6 #include "PartSet_Tools.h"
7 #include "PartSet_WidgetPoint2d.h"
8 #include "PartSet_WidgetPoint2dDistance.h"
9 #include "PartSet_WidgetPoint2DFlyout.h"
10 #include "PartSet_WidgetShapeSelector.h"
11 #include "PartSet_WidgetMultiSelector.h"
12 #include "PartSet_WidgetEditor.h"
13 #include "PartSet_WidgetFileSelector.h"
14 #include "PartSet_WidgetSketchCreator.h"
15 #include "PartSet_SketcherMgr.h"
16 #include "PartSet_SketcherReetntrantMgr.h"
17 #include "PartSet_MenuMgr.h"
18 #include "PartSet_CustomPrs.h"
19 #include "PartSet_IconFactory.h"
20 #include "PartSet_WidgetChoice.h"
21 #include "PartSet_OverconstraintListener.h"
23 #include "PartSet_Filters.h"
24 #include "PartSet_FilterInfinite.h"
26 #include <PartSetPlugin_Remove.h>
27 #include <PartSetPlugin_Part.h>
28 #include <PartSetPlugin_Duplicate.h>
30 #include <ModuleBase_Operation.h>
31 #include <ModuleBase_OperationAction.h>
32 #include <ModuleBase_IViewer.h>
33 #include <ModuleBase_IViewWindow.h>
34 #include <ModuleBase_IPropertyPanel.h>
35 #include <ModuleBase_WidgetEditor.h>
36 #include <ModuleBase_WidgetValidated.h>
37 #include <ModuleBase_FilterFactory.h>
38 #include <ModuleBase_Tools.h>
39 #include <ModuleBase_OperationFeature.h>
41 #include <ModelAPI_Object.h>
42 #include <ModelAPI_Events.h>
43 #include <ModelAPI_Validator.h>
44 #include <ModelAPI_Data.h>
45 #include <ModelAPI_Session.h>
46 #include <ModelAPI_ResultBody.h>
47 #include <ModelAPI_AttributeString.h>
49 #include <GeomDataAPI_Point2D.h>
50 #include <GeomDataAPI_Point.h>
51 #include <GeomDataAPI_Dir.h>
53 #include <XGUI_Displayer.h>
54 #include <XGUI_Workshop.h>
55 #include <XGUI_OperationMgr.h>
56 #include <XGUI_PropertyPanel.h>
57 #include <XGUI_ModuleConnector.h>
58 #include <XGUI_ContextMenuMgr.h>
59 #include <XGUI_Tools.h>
60 #include <XGUI_ObjectsBrowser.h>
61 #include <XGUI_SelectionMgr.h>
62 #include <XGUI_DataModel.h>
63 #include <XGUI_ErrorMgr.h>
65 #include <SketchPlugin_Feature.h>
66 #include <SketchPlugin_Sketch.h>
67 #include <SketchPlugin_ConstraintAngle.h>
68 #include <SketchPlugin_ConstraintLength.h>
69 #include <SketchPlugin_ConstraintDistance.h>
70 #include <SketchPlugin_ConstraintParallel.h>
71 #include <SketchPlugin_ConstraintPerpendicular.h>
72 #include <SketchPlugin_ConstraintRadius.h>
74 #include <SketcherPrs_SymbolPrs.h>
75 #include <SketcherPrs_Tools.h>
77 #include <Events_Loop.h>
78 #include <Config_PropManager.h>
79 #include <Config_Keywords.h>
81 #include <StdSelect_TypeOfFace.hxx>
82 #include <TopoDS_Vertex.hxx>
84 #include <TopoDS_Shape.hxx>
85 #include <BRep_Tool.hxx>
86 #include <AIS_Dimension.hxx>
89 #include <QMouseEvent>
92 #include <QApplication>
93 #include <QMessageBox>
94 #include <QMainWindow>
97 #include <GeomAlgoAPI_FaceBuilder.h>
98 #include <GeomDataAPI_Dir.h>
100 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
106 /*!Create and return new instance of XGUI_Module*/
107 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
109 return new PartSet_Module(theWshop);
112 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
113 : ModuleBase_IModule(theWshop),
116 new PartSet_IconFactory();
118 mySketchMgr = new PartSet_SketcherMgr(this);
119 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
121 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
122 XGUI_Workshop* aWorkshop = aConnector->workshop();
124 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
125 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
126 this, SLOT(onOperationActivatedByPreselection()));
128 ModuleBase_IViewer* aViewer = theWshop->viewer();
129 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
130 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
131 connect(aViewer, SIGNAL(viewTransformed(int)),
132 SLOT(onViewTransformed(int)));
133 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
134 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
135 myMenuMgr = new PartSet_MenuMgr(this);
136 myCustomPrs = new PartSet_CustomPrs(theWshop);
138 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
140 Events_Loop* aLoop = Events_Loop::loop();
141 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
143 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
144 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
146 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
147 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
149 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
150 "Reference shape wireframe color in operation", Config_Prop::Color,
151 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
152 Config_PropManager::registerProp("Visualization", "operation_result_color",
153 "Result shape wireframe color in operation", Config_Prop::Color,
154 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
155 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
156 "Multi selector item color in operation", Config_Prop::Color,
157 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
160 PartSet_Module::~PartSet_Module()
162 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
163 for (; aIt.More(); aIt.Next()) {
164 Handle(SelectMgr_Filter) aFilter = aIt.Value();
165 if (!aFilter.IsNull())
169 delete myOverconstraintListener;
172 void PartSet_Module::activateSelectionFilters()
174 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
175 for (; aIt.More(); aIt.Next()) {
176 Handle(SelectMgr_Filter) aFilter = aIt.Value();
177 if (!aFilter.IsNull())
178 myWorkshop->viewer()->addSelectionFilter(aFilter);
182 void PartSet_Module::deactivateSelectionFilters()
184 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
185 for (; aIt.More(); aIt.Next()) {
186 Handle(SelectMgr_Filter) aFilter = aIt.Value();
187 if (!aFilter.IsNull())
188 myWorkshop->viewer()->removeSelectionFilter(aFilter);
192 void PartSet_Module::registerValidators()
194 //Registering of validators
195 SessionPtr aMgr = ModelAPI_Session::get();
196 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
197 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
198 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
199 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
200 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
201 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
202 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
203 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
204 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
205 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
206 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
207 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
208 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
209 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
210 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
211 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
212 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
213 aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator);
216 void PartSet_Module::registerFilters()
218 //Registering of selection filters
219 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
220 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
223 void PartSet_Module::registerProperties()
225 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
227 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
228 Config_Prop::Integer, SKETCH_WIDTH);
229 Config_PropManager::registerProp("Sketch planes", "rotate_to_plane", "Rotate to plane when selected",
230 Config_Prop::Boolean, "false");
233 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
235 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
238 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
240 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
241 mySketchMgr->commitNestedSketch(theOperation);
244 /// Restart sketcher operations automatically
245 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
247 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
248 if (aFOperation && !aFOperation->isEditOperation()) {
249 // the selection is cleared after commit the create operation
250 // in order to do not use the same selected objects in the restarted operation
251 // for common behaviour, the selection is cleared even if the operation is not restarted
252 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
253 XGUI_Workshop* aWorkshop = aConnector->workshop();
254 aWorkshop->selector()->clearSelection();
259 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
261 /// Restart sketcher operations automatically
262 mySketchReentrantMgr->operationAborted(theOperation);
265 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
267 /// Restart sketcher operations automatically
268 mySketchReentrantMgr->operationStarted(theOperation);
270 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
271 mySketchMgr->startSketch(theOperation);
273 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
274 mySketchMgr->startNestedSketch(theOperation);
277 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
279 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
280 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
284 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
286 ModuleBase_IModule::operationResumed(theOperation);
288 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
290 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
291 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
295 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
297 bool isModified = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false) ||
298 myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
300 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
301 mySketchMgr->stopNestedSketch(theOperation);
304 //VSV: Viewer is updated on feature update and redisplay
306 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
307 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
308 aDisplayer->updateViewer();
311 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
312 aLast = myHasConstraintShown.end();
313 for (; anIt != aLast; anIt++) {
314 myHasConstraintShown[anIt.key()];
315 mySketchMgr->onShowConstraintsToggle(anIt.value(), myHasConstraintShown[anIt.key()]);
319 ModuleBase_Operation* PartSet_Module::currentOperation() const
321 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
322 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
323 return anOpMgr->currentOperation();
326 bool PartSet_Module::canUndo() const
328 bool aCanUndo = false;
329 SessionPtr aMgr = ModelAPI_Session::get();
330 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
331 aCanUndo = !aMgr->isOperation();
332 if (!aCanUndo) // check the enable state additionally by sketch manager
333 aCanUndo = aMgr->canUndo();
338 bool PartSet_Module::canRedo() const
340 bool aCanRedo = false;
341 SessionPtr aMgr = ModelAPI_Session::get();
342 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
343 aCanRedo = !aMgr->isOperation();
344 if (!aCanRedo) // check the enable state additionally by sketch manager
345 aCanRedo = aMgr->canRedo();
350 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
353 if (theActionId == "MOVE_CMD") {
354 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
356 // part features can not be moved in the history.
357 if (aFeature->getKind() == PartSetPlugin_Part::ID())
364 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
366 // the sketch manager put the restriction to the objects erase
367 return mySketchMgr->canEraseObject(theObject);
370 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
372 // the sketch manager put the restriction to the objects display
373 return mySketchMgr->canDisplayObject(theObject);
376 void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
378 mySketchMgr->processHiddenObject(theObjects);
381 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
383 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
385 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
386 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
387 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
388 if (isSketchOp || isNestedOp) {
389 // in active sketch operation it is possible to activate operation object in selection
390 // in the edit operation, e.g. points of the line can be moved when the line is edited
391 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
392 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
397 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
399 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
402 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
404 myMenuMgr->updateViewerMenu(theStdActions);
407 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
409 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
410 if (anError.isEmpty())
411 anError = sketchMgr()->getFeatureError(theFeature);
416 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
417 QStringList& theIds) const
419 myMenuMgr->grantedOperationIds(theOperation, theIds);
421 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
422 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
423 XGUI_Workshop* aWorkshop = aConnector->workshop();
425 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
429 void PartSet_Module::activeSelectionModes(QIntList& theModes)
432 if (mySketchMgr->activeSketch().get())
433 PartSet_SketcherMgr::sketchSelectionModes(theModes);
436 bool PartSet_Module::isMouseOverWindow()
438 return mySketchMgr->isMouseOverWindow();
441 void PartSet_Module::closeDocument()
446 void PartSet_Module::clearViewer()
448 myCustomPrs->clearPrs();
450 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
451 XGUI_Workshop* aWorkshop = aConnector->workshop();
452 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
453 aDisplayer->deactivateSelectionFilters();
456 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
458 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
462 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
463 // we have to manually activate the sketch label in edit mode
464 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
465 aPanel->activateWidget(aPanel->modelWidgets().first());
469 void PartSet_Module::onSelectionChanged()
471 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
475 bool isSketcherOp = false;
476 // An edit operation is enable only if the current opeation is the sketch operation
477 if (mySketchMgr->activeSketch()) {
478 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
479 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
482 // Editing of constraints can be done on selection
483 ModuleBase_ISelection* aSelect = myWorkshop->selection();
484 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
485 if (aSelected.size() == 1) {
486 ModuleBase_ViewerPrs aPrs = aSelected.first();
487 ObjectPtr aObject = aPrs.object();
488 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
490 std::string aId = aFeature->getKind();
491 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
492 (aId == SketchPlugin_ConstraintLength::ID()) ||
493 (aId == SketchPlugin_ConstraintDistance::ID()) ||
494 (aId == SketchPlugin_ConstraintAngle::ID())) {
495 editFeature(aFeature);
502 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
504 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
505 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
506 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
509 void PartSet_Module::onOperationActivatedByPreselection()
511 if (!mySketchReentrantMgr->canBeCommittedByPreselection())
513 mySketchMgr->operationActivatedByPreselection();
516 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
517 Config_WidgetAPI* theWidgetApi, std::string theParentId)
519 ModuleBase_IWorkshop* aWorkshop = workshop();
520 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
521 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
522 ModuleBase_ModelWidget* aWgt = NULL;
523 if (theType == "sketch-start-label") {
524 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
525 theWidgetApi, theParentId, mySketchMgr->showConstraintStates());
526 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
527 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
528 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool, int)),
529 mySketchMgr, SLOT(onShowConstraintsToggle(bool, int)));
531 } else if (theType == "sketch-2dpoint_selector") {
532 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
533 theWidgetApi, theParentId);
534 aPointWgt->setSketch(mySketchMgr->activeSketch());
535 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
537 }else if (theType == "sketch-2dpoint_flyout_selector") {
538 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
539 theWidgetApi, theParentId);
540 aPointWgt->setSketch(mySketchMgr->activeSketch());
541 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
543 } else if (theType == "point2ddistance") {
544 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
545 aWorkshop, theWidgetApi, theParentId);
546 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
548 } else if (theType == "sketch_shape_selector") {
549 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
550 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
551 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
552 aWgt = aShapeSelectorWgt;
553 } else if (theType == "sketch_multi_selector") {
554 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
555 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
556 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
557 aWgt = aShapeSelectorWgt;
558 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
559 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
560 } else if (theType == "export_file_selector") {
561 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
562 } else if (theType == "sketch_launcher") {
563 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
564 } else if (theType == "module_choice") {
565 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi, theParentId);
566 connect(aWgt, SIGNAL(itemSelected(int)), SLOT(onBooleanOperationChange(int)));
571 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
573 ModuleBase_ModelWidget* anActiveWidget = 0;
575 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
576 if (!anActiveWidget) {
577 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
579 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
580 anActiveWidget = aPanel->activeWidget();
583 return anActiveWidget;
586 bool PartSet_Module::deleteObjects()
588 bool isProcessed = false;
590 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
591 XGUI_Workshop* aWorkshop = aConnector->workshop();
592 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
594 //SessionPtr aMgr = ModelAPI_Session::get();
595 // 1. check whether the delete should be processed in the module
596 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
597 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
598 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
599 if (isSketchOp || isNestedOp) {
601 // 2. find selected presentations
602 // selected objects should be collected before the current operation abort because
603 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
604 ModuleBase_ISelection* aSel = workshop()->selection();
605 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
606 // if there are no selected objects in the viewer, that means that the selection in another
607 // place cased this method. It is necessary to return the false value to understande in above
608 // method that delete is not processed
609 if (aSelectedObj.count() == 0)
612 // avoid delete of the objects, which are not belong to the current sketch
613 // in order to do not delete results of other sketches
614 QObjectPtrList aSketchObjects;
615 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
616 for ( ; anIt != aLast; anIt++) {
617 ObjectPtr anObject = *anIt;
618 if (mySketchMgr->isObjectOfSketch(anObject)) {
619 // sketch feature should be used in this list because workshop deletes features only
620 // results are skipped
621 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
622 aSketchObjects.append(aSketchFeature);
625 // if the selection contains only local selected presentations from other sketches,
626 // the Delete operation should not be done at all
627 if (aSketchObjects.size() == 0)
630 // 3. start operation
631 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
632 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
634 // the active nested sketch operation should be aborted unconditionally
635 // the Delete action should be additionally granted for the Sketch operation
636 // in order to do not abort/commit it
637 if (!anOpMgr->canStartOperation(anOpAction->id()))
638 return true; // the objects are processed but can not be deleted
640 anOpMgr->startOperation(anOpAction);
642 // 4. delete features
643 // sketch feature should be skipped, only sub-features can be removed
644 // when sketch operation is active
645 aWorkshop->deleteFeatures(aSketchObjects);
647 anOpMgr->commitOperation();
652 void PartSet_Module::onFeatureTriggered()
654 QAction* aCmd = dynamic_cast<QAction*>(sender());
655 if (aCmd->isCheckable() && aCmd->isChecked()) {
656 // 1. check whether the delete should be processed in the module
657 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
658 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
660 // in case if in the viewer nothing is displayed, the create operation should not be
661 // comitted even if all values of the feature are initialized
662 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
663 // the action information should be saved before the operation is aborted
664 // because this abort leads to update command status, which unchecks this action
665 anOperation->abort();
666 launchOperation(aCmd->data().toString());
670 ModuleBase_IModule::onFeatureTriggered();
673 void PartSet_Module::launchOperation(const QString& theCmdId)
675 if (myWorkshop->currentOperation() &&
676 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
677 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates = mySketchMgr->showConstraintStates();
678 myHasConstraintShown = aShownStates;
680 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
681 // Show constraints if a constraint was anOperation
682 mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Geometrical);
683 mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Dimensional);
685 ModuleBase_IModule::launchOperation(theCmdId);
689 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
691 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
692 if (!anAIS.IsNull()) {
693 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
694 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
695 if (!aDim.IsNull()) {
696 aCtx->SetZLayer(aDim, myVisualLayerId);
698 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
700 aCtx->SetZLayer(aCons, myVisualLayerId);
705 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
708 // it should be recomputed in order to disappear in the viewer if the corresponded object
710 //if (myCustomPrs->isActive())
711 // myCustomPrs->redisplay(theObject, false);
714 void PartSet_Module::onViewTransformed(int theTrsfType)
716 // Set length of arrows constant in pixel size
717 // if the operation is panning or rotate or panglobal then do nothing
718 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
720 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
721 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
722 if (aContext.IsNull())
725 //Handle(V3d_View) aView = aViewer->activeView();
727 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
728 XGUI_Workshop* aWorkshop = aConnector->workshop();
729 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
730 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
731 Handle(V3d_View) aView;
733 for (aV3dViewer->InitDefinedViews();
734 aV3dViewer->MoreDefinedViews();
735 aV3dViewer->NextDefinedViews()) {
736 Handle(V3d_View) aV = aV3dViewer->DefinedView();
737 double aS = aV->Scale();
745 double aLen = aView->Convert(20);
747 double aPrevLen = SketcherPrs_Tools::getArrowSize();
748 SketcherPrs_Tools::setArrowSize(aLen);
749 const double aPrevScale = aViewer->Scale(aViewer->activeView());
750 const double aCurScale = aViewer->activeView()->Camera()->Scale();
751 aViewer->SetScale(aViewer->activeView(), aCurScale);
752 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
753 bool isModified = false;
754 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
755 foreach (AISObjectPtr aAIS, aPrsList) {
756 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
758 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
759 if (!aDim.IsNull()) {
760 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
761 aContext->Redisplay(aDim, false);
766 aDisplayer->updateViewer();
769 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature, const ModuleBase_CustomizeFlag& theFlag,
770 const bool theUpdateViewer)
772 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
775 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
776 const bool theUpdateViewer)
778 myCustomPrs->deactivate(theFlag, theUpdateViewer);
781 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
782 const bool theUpdateViewer)
784 bool isRedisplayed = false;
785 if (myCustomPrs->isActive(theFlag))
786 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
788 return isRedisplayed;
791 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
793 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
795 QLabel* aLabel = aOB->activeDocLabel();
796 aLabel->installEventFilter(myMenuMgr);
797 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
798 SLOT(onActiveDocPopup(const QPoint&)));
799 //QPalette aPalet = aLabel->palette();
800 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
801 //aLabel->setPalette(aPalet);
802 aOB->treeView()->setExpandsOnDoubleClick(false);
803 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
804 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
808 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
810 SessionPtr aMgr = ModelAPI_Session::get();
811 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
813 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
814 XGUI_Workshop* aWorkshop = aConnector->workshop();
815 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
817 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
820 aMenu.addAction(aActivatePartAction);
821 aMenu.exec(aHeader->mapToGlobal(thePnt));
825 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
828 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
830 /// If last line finished on vertex the lines creation sequence has to be break
831 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
833 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
834 // if there is an active widget, find the presented object in it
836 anActiveWidget = aPanel->preselectionWidget();
838 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
840 if (aWidgetValidated)
841 anObject = aWidgetValidated->findPresentedObject(theAIS);
847 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
849 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
850 int aSelected = aObjects.size();
851 SessionPtr aMgr = ModelAPI_Session::get();
852 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
854 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
855 if (aSelected == 1) {
856 bool hasResult = false;
857 bool hasFeature = false;
858 bool hasParameter = false;
859 bool hasSubFeature = false;
860 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
862 ObjectPtr aObject = aObjects.first();
864 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
865 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
866 bool isPart = aPart.get() ||
867 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
869 DocumentPtr aPartDoc;
871 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
873 if (aPart.get()) // this may be null is Part feature is disabled
874 aPartDoc = aPart->partDoc();
876 theMenu->addAction(aActivatePartAction);
877 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
879 } else if (aObject->document() == aMgr->activeDocument()) {
880 if (hasParameter || hasFeature) {
881 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
882 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
883 if (aCurrentOp && aFeature.get()) {
884 if (aCurrentOp->id().toStdString() == aFeature->getKind())
885 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
890 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
892 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
895 bool aNotDeactivate = (aCurrentOp == 0);
896 if (!aNotDeactivate) {
897 aActivatePartAction->setEnabled(false);
901 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
903 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
904 // Do not change activation of parts if an operation active
905 static QStringList aAllowActivationList;
906 if (aAllowActivationList.isEmpty())
907 aAllowActivationList <<
908 QString(PartSetPlugin_Part::ID().c_str()) <<
909 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
910 QString(PartSetPlugin_Remove::ID().c_str());
911 if (myWorkshop->currentOperation() &&
912 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
914 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
915 XGUI_Workshop* aWorkshop = aConnector->workshop();
916 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
917 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
918 QPalette aPalet = aLabel->palette();
920 SessionPtr aMgr = ModelAPI_Session::get();
921 DocumentPtr aActiveDoc = aMgr->activeDocument();
922 if (aActivePartIndex.isValid())
923 aTreeView->setExpanded(aActivePartIndex, false);
924 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
925 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
926 if (aActivePartIndex.isValid())
927 aTreeView->setExpanded(aActivePartIndex, true);
929 aLabel->setPalette(aPalet);
930 aWorkshop->updateCommandStatus();
932 // Update displayed objects in order to update active color
933 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
934 QObjectPtrList aObjects = aDisplayer->displayedObjects();
936 foreach(ObjectPtr aObj, aObjects) {
937 //TODO: replace by redisplay event.
938 aHidden = !aObj->data() || !aObj->data()->isValid() ||
939 aObj->isDisabled() || (!aObj->isDisplayed());
941 aDisplayer->redisplay(aObj, false);
943 aDisplayer->updateViewer();
947 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
949 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
951 SessionPtr aMgr = ModelAPI_Session::get();
952 if (!theIndex.isValid()) {
953 aMgr->setActiveDocument(aMgr->moduleDocument());
956 if (theIndex.column() != 0) // Use only first column
959 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
960 XGUI_Workshop* aWorkshop = aConnector->workshop();
961 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
962 // De not use non editable Indexes
963 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
965 ObjectPtr aObj = aDataModel->object(theIndex);
967 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
968 if (!aPart.get()) { // Probably this is Feature
969 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
970 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
971 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
974 if (aPart.get()) { // if this is a part
975 if (aPart->partDoc() == aMgr->activeDocument()) {
976 myMenuMgr->activatePartSet();
984 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
986 // z layer is created for all started operations in order to visualize operation AIS presentation
988 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
989 if (aContext.IsNull())
992 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
993 if (myVisualLayerId == 0) {
994 if (myVisualLayerId == 0)
995 aViewer->AddZLayer(myVisualLayerId);
997 TColStd_SequenceOfInteger aZList;
998 aViewer->GetAllZLayers(aZList);
1000 for (int i = 1; i <= aZList.Length(); i++) {
1001 if (aZList(i) == myVisualLayerId) {
1007 aViewer->AddZLayer(myVisualLayerId);
1009 // if there is an active operation with validated widget,
1010 // the filters of this widget should be activated in the created view
1011 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1013 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1014 if (anActiveWidget) {
1015 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1017 aWSelector->activateSelectionAndFilters(true);
1022 //******************************************************
1023 void PartSet_Module::widgetStateChanged(int thePreviousState)
1025 mySketchMgr->widgetStateChanged(thePreviousState);
1028 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1030 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1033 //******************************************************
1034 void PartSet_Module::beforeOperationStarted(ModuleBase_Operation* theOperation)
1038 //******************************************************
1039 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1041 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1042 mySketchMgr->stopSketch(theOperation);
1046 //******************************************************
1047 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1049 GeomShapePtr aGeomShape;
1051 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1052 if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1053 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1058 //******************************************************
1059 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1060 const GeomShapePtr& theGeomShape)
1062 AttributePtr anAttribute;
1063 GeomShapePtr aGeomShape = theGeomShape;
1064 if (!aGeomShape.get()) {
1065 // processing shape of result, e.g. sketch circle center is selected, this is a result
1066 // the geom shape is empty, the shape of result should be used
1067 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1068 if (aResult.get()) {
1069 aGeomShape = aResult->shape();
1073 if (aGeomShape.get()) {
1074 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1075 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1076 mySketchMgr->activeSketch());
1081 //******************************************************
1082 void PartSet_Module::getColor(const ObjectPtr& theObject, std::vector<int>& theColor)
1084 if (myOverconstraintListener->isConflictingObject(theObject)) {
1085 myOverconstraintListener->getConflictingColor(theColor);
1089 //******************************************************
1090 void PartSet_Module::onBooleanOperationChange(int theOperation)
1092 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1095 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1096 switch (theOperation) {
1098 aPanel->setWindowTitle(tr("Cut"));
1101 aPanel->setWindowTitle(tr("Fuse"));
1104 aPanel->setWindowTitle(tr("Common"));