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>
64 #include <XGUI_CustomPrs.h>
66 #include <SketchPlugin_Feature.h>
67 #include <SketchPlugin_Sketch.h>
68 #include <SketchPlugin_ConstraintAngle.h>
69 #include <SketchPlugin_ConstraintLength.h>
70 #include <SketchPlugin_ConstraintDistance.h>
71 #include <SketchPlugin_ConstraintParallel.h>
72 #include <SketchPlugin_ConstraintPerpendicular.h>
73 #include <SketchPlugin_ConstraintRadius.h>
75 #include <SketcherPrs_SymbolPrs.h>
76 #include <SketcherPrs_Tools.h>
78 #include <Events_Loop.h>
79 #include <Config_PropManager.h>
80 #include <Config_Keywords.h>
82 #include <StdSelect_TypeOfFace.hxx>
83 #include <TopoDS_Vertex.hxx>
85 #include <TopoDS_Shape.hxx>
86 #include <BRep_Tool.hxx>
87 #include <AIS_Dimension.hxx>
90 #include <QMouseEvent>
93 #include <QApplication>
94 #include <QMessageBox>
95 #include <QMainWindow>
98 #include <GeomAlgoAPI_FaceBuilder.h>
99 #include <GeomDataAPI_Dir.h>
101 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
107 /*!Create and return new instance of XGUI_Module*/
108 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
110 return new PartSet_Module(theWshop);
113 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
114 : ModuleBase_IModule(theWshop),
117 new PartSet_IconFactory();
119 mySketchMgr = new PartSet_SketcherMgr(this);
120 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
122 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
123 XGUI_Workshop* aWorkshop = aConnector->workshop();
125 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
126 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
127 this, SLOT(onOperationActivatedByPreselection()));
129 ModuleBase_IViewer* aViewer = theWshop->viewer();
130 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
131 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
132 connect(aViewer, SIGNAL(viewTransformed(int)),
133 SLOT(onViewTransformed(int)));
134 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
135 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
136 myMenuMgr = new PartSet_MenuMgr(this);
137 myCustomPrs = new PartSet_CustomPrs(theWshop);
139 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
141 Events_Loop* aLoop = Events_Loop::loop();
142 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
144 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
145 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
147 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
148 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
150 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
151 "Reference shape wireframe color in operation", Config_Prop::Color,
152 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
153 Config_PropManager::registerProp("Visualization", "operation_result_color",
154 "Result shape wireframe color in operation", Config_Prop::Color,
155 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
156 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
157 "Multi selector item color in operation", Config_Prop::Color,
158 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
161 PartSet_Module::~PartSet_Module()
163 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
164 for (; aIt.More(); aIt.Next()) {
165 Handle(SelectMgr_Filter) aFilter = aIt.Value();
166 if (!aFilter.IsNull())
170 delete myOverconstraintListener;
173 void PartSet_Module::activateSelectionFilters()
175 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
176 for (; aIt.More(); aIt.Next()) {
177 Handle(SelectMgr_Filter) aFilter = aIt.Value();
178 if (!aFilter.IsNull())
179 myWorkshop->viewer()->addSelectionFilter(aFilter);
183 void PartSet_Module::deactivateSelectionFilters()
185 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
186 for (; aIt.More(); aIt.Next()) {
187 Handle(SelectMgr_Filter) aFilter = aIt.Value();
188 if (!aFilter.IsNull())
189 myWorkshop->viewer()->removeSelectionFilter(aFilter);
193 void PartSet_Module::registerValidators()
195 //Registering of validators
196 SessionPtr aMgr = ModelAPI_Session::get();
197 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
198 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
199 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
200 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
201 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
202 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
203 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
204 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
205 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
206 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
207 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
208 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
209 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
210 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
211 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
212 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
213 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
214 aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator);
217 void PartSet_Module::registerFilters()
219 //Registering of selection filters
220 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
221 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
224 void PartSet_Module::registerProperties()
226 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
228 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
229 Config_Prop::Integer, SKETCH_WIDTH);
230 Config_PropManager::registerProp("Sketch planes", "rotate_to_plane", "Rotate to plane when selected",
231 Config_Prop::Boolean, "false");
234 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
236 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
239 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
241 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
242 mySketchMgr->commitNestedSketch(theOperation);
245 /// Restart sketcher operations automatically
246 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
248 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
249 if (aFOperation && !aFOperation->isEditOperation()) {
250 // the selection is cleared after commit the create operation
251 // in order to do not use the same selected objects in the restarted operation
252 // for common behaviour, the selection is cleared even if the operation is not restarted
253 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
254 XGUI_Workshop* aWorkshop = aConnector->workshop();
255 aWorkshop->selector()->clearSelection();
260 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
262 /// Restart sketcher operations automatically
263 mySketchReentrantMgr->operationAborted(theOperation);
266 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
268 /// Restart sketcher operations automatically
269 mySketchReentrantMgr->operationStarted(theOperation);
271 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
272 mySketchMgr->startSketch(theOperation);
274 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
275 mySketchMgr->startNestedSketch(theOperation);
278 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
280 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
281 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
285 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
287 ModuleBase_IModule::operationResumed(theOperation);
289 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
291 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
292 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
296 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
298 bool isModified = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false) ||
299 myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
301 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
302 mySketchMgr->stopNestedSketch(theOperation);
305 //VSV: Viewer is updated on feature update and redisplay
307 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
308 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
309 aDisplayer->updateViewer();
312 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
313 aLast = myHasConstraintShown.end();
314 for (; anIt != aLast; anIt++) {
315 myHasConstraintShown[anIt.key()];
316 mySketchMgr->onShowConstraintsToggle(anIt.value(), myHasConstraintShown[anIt.key()]);
320 ModuleBase_Operation* PartSet_Module::currentOperation() const
322 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
323 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
324 return anOpMgr->currentOperation();
327 bool PartSet_Module::canUndo() const
329 bool aCanUndo = false;
330 SessionPtr aMgr = ModelAPI_Session::get();
331 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
332 aCanUndo = !aMgr->isOperation();
333 if (!aCanUndo) // check the enable state additionally by sketch manager
334 aCanUndo = aMgr->canUndo();
339 bool PartSet_Module::canRedo() const
341 bool aCanRedo = false;
342 SessionPtr aMgr = ModelAPI_Session::get();
343 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
344 aCanRedo = !aMgr->isOperation();
345 if (!aCanRedo) // check the enable state additionally by sketch manager
346 aCanRedo = aMgr->canRedo();
351 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
354 if (theActionId == "MOVE_CMD") {
355 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
357 // part features can not be moved in the history.
358 if (aFeature->getKind() == PartSetPlugin_Part::ID())
365 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
367 // the sketch manager put the restriction to the objects erase
368 return mySketchMgr->canEraseObject(theObject);
371 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
373 // the sketch manager put the restriction to the objects display
374 return mySketchMgr->canDisplayObject(theObject);
377 void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
379 mySketchMgr->processHiddenObject(theObjects);
382 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
384 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
386 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
387 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
388 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
389 if (isSketchOp || isNestedOp) {
390 // in active sketch operation it is possible to activate operation object in selection
391 // in the edit operation, e.g. points of the line can be moved when the line is edited
392 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
393 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
398 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
400 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
403 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
405 myMenuMgr->updateViewerMenu(theStdActions);
408 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
410 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
411 if (anError.isEmpty())
412 anError = sketchMgr()->getFeatureError(theFeature);
417 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
418 QStringList& theIds) const
420 myMenuMgr->grantedOperationIds(theOperation, theIds);
422 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
423 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
424 XGUI_Workshop* aWorkshop = aConnector->workshop();
426 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
430 void PartSet_Module::activeSelectionModes(QIntList& theModes)
433 if (mySketchMgr->activeSketch().get())
434 PartSet_SketcherMgr::sketchSelectionModes(theModes);
437 bool PartSet_Module::isMouseOverWindow()
439 return mySketchMgr->isMouseOverWindow();
442 void PartSet_Module::closeDocument()
447 void PartSet_Module::clearViewer()
449 myCustomPrs->clearPrs();
451 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
452 XGUI_Workshop* aWorkshop = aConnector->workshop();
453 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
454 aDisplayer->deactivateSelectionFilters();
457 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
459 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
463 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
464 // we have to manually activate the sketch label in edit mode
465 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
466 aPanel->activateWidget(aPanel->modelWidgets().first());
470 void PartSet_Module::onSelectionChanged()
472 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
476 bool isSketcherOp = false;
477 // An edit operation is enable only if the current opeation is the sketch operation
478 if (mySketchMgr->activeSketch()) {
479 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
480 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
483 // Editing of constraints can be done on selection
484 ModuleBase_ISelection* aSelect = myWorkshop->selection();
485 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
486 if (aSelected.size() == 1) {
487 ModuleBase_ViewerPrs aPrs = aSelected.first();
488 ObjectPtr aObject = aPrs.object();
489 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
491 std::string aId = aFeature->getKind();
492 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
493 (aId == SketchPlugin_ConstraintLength::ID()) ||
494 (aId == SketchPlugin_ConstraintDistance::ID()) ||
495 (aId == SketchPlugin_ConstraintAngle::ID())) {
496 editFeature(aFeature);
503 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
505 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
506 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
507 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
510 void PartSet_Module::onOperationActivatedByPreselection()
512 if (!mySketchReentrantMgr->canBeCommittedByPreselection())
514 mySketchMgr->operationActivatedByPreselection();
517 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
518 Config_WidgetAPI* theWidgetApi, std::string theParentId)
520 ModuleBase_IWorkshop* aWorkshop = workshop();
521 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
522 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
523 ModuleBase_ModelWidget* aWgt = NULL;
524 if (theType == "sketch-start-label") {
525 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
526 theWidgetApi, theParentId, mySketchMgr->showConstraintStates());
527 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
528 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
529 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool, int)),
530 mySketchMgr, SLOT(onShowConstraintsToggle(bool, int)));
532 } else if (theType == "sketch-2dpoint_selector") {
533 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
534 theWidgetApi, theParentId);
535 aPointWgt->setSketch(mySketchMgr->activeSketch());
536 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
538 }else if (theType == "sketch-2dpoint_flyout_selector") {
539 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
540 theWidgetApi, theParentId);
541 aPointWgt->setSketch(mySketchMgr->activeSketch());
542 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
544 } else if (theType == "point2ddistance") {
545 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
546 aWorkshop, theWidgetApi, theParentId);
547 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
549 } else if (theType == "sketch_shape_selector") {
550 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
551 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
552 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
553 aWgt = aShapeSelectorWgt;
554 } else if (theType == "sketch_multi_selector") {
555 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
556 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
557 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
558 aWgt = aShapeSelectorWgt;
559 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
560 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
561 } else if (theType == "export_file_selector") {
562 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
563 } else if (theType == "sketch_launcher") {
564 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
565 } else if (theType == "module_choice") {
566 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi, theParentId);
567 connect(aWgt, SIGNAL(itemSelected(int)), SLOT(onBooleanOperationChange(int)));
572 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
574 ModuleBase_ModelWidget* anActiveWidget = 0;
576 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
577 if (!anActiveWidget) {
578 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
580 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
581 anActiveWidget = aPanel->activeWidget();
584 return anActiveWidget;
587 bool PartSet_Module::deleteObjects()
589 bool isProcessed = false;
591 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
592 XGUI_Workshop* aWorkshop = aConnector->workshop();
593 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
595 //SessionPtr aMgr = ModelAPI_Session::get();
596 // 1. check whether the delete should be processed in the module
597 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
598 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
599 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
600 if (isSketchOp || isNestedOp) {
602 // 2. find selected presentations
603 // selected objects should be collected before the current operation abort because
604 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
605 ModuleBase_ISelection* aSel = workshop()->selection();
606 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
607 // if there are no selected objects in the viewer, that means that the selection in another
608 // place cased this method. It is necessary to return the false value to understande in above
609 // method that delete is not processed
610 if (aSelectedObj.count() == 0)
613 // avoid delete of the objects, which are not belong to the current sketch
614 // in order to do not delete results of other sketches
615 QObjectPtrList aSketchObjects;
616 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
617 for ( ; anIt != aLast; anIt++) {
618 ObjectPtr anObject = *anIt;
619 if (mySketchMgr->isObjectOfSketch(anObject)) {
620 // sketch feature should be used in this list because workshop deletes features only
621 // results are skipped
622 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
623 aSketchObjects.append(aSketchFeature);
626 // if the selection contains only local selected presentations from other sketches,
627 // the Delete operation should not be done at all
628 if (aSketchObjects.size() == 0)
631 // 3. start operation
632 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
633 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
635 // the active nested sketch operation should be aborted unconditionally
636 // the Delete action should be additionally granted for the Sketch operation
637 // in order to do not abort/commit it
638 if (!anOpMgr->canStartOperation(anOpAction->id()))
639 return true; // the objects are processed but can not be deleted
641 anOpMgr->startOperation(anOpAction);
643 // 4. delete features
644 // sketch feature should be skipped, only sub-features can be removed
645 // when sketch operation is active
646 aWorkshop->deleteFeatures(aSketchObjects);
648 anOpMgr->commitOperation();
653 void PartSet_Module::onFeatureTriggered()
655 QAction* aCmd = dynamic_cast<QAction*>(sender());
656 if (aCmd->isCheckable() && aCmd->isChecked()) {
657 // 1. check whether the delete should be processed in the module
658 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
659 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
661 // in case if in the viewer nothing is displayed, the create operation should not be
662 // comitted even if all values of the feature are initialized
663 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
664 // the action information should be saved before the operation is aborted
665 // because this abort leads to update command status, which unchecks this action
666 anOperation->abort();
667 launchOperation(aCmd->data().toString());
671 ModuleBase_IModule::onFeatureTriggered();
674 void PartSet_Module::launchOperation(const QString& theCmdId)
676 if (myWorkshop->currentOperation() &&
677 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
678 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates = mySketchMgr->showConstraintStates();
679 myHasConstraintShown = aShownStates;
681 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
682 // Show constraints if a constraint was anOperation
683 mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Geometrical);
684 mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Dimensional);
686 ModuleBase_IModule::launchOperation(theCmdId);
690 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
692 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
693 if (!anAIS.IsNull()) {
694 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
695 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
696 if (!aDim.IsNull()) {
697 aCtx->SetZLayer(aDim, myVisualLayerId);
699 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
701 aCtx->SetZLayer(aCons, myVisualLayerId);
706 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
709 // it should be recomputed in order to disappear in the viewer if the corresponded object
711 //if (myCustomPrs->isActive())
712 // myCustomPrs->redisplay(theObject, false);
715 void PartSet_Module::onViewTransformed(int theTrsfType)
717 // Set length of arrows constant in pixel size
718 // if the operation is panning or rotate or panglobal then do nothing
719 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
721 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
722 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
723 if (aContext.IsNull())
726 //Handle(V3d_View) aView = aViewer->activeView();
728 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
729 XGUI_Workshop* aWorkshop = aConnector->workshop();
730 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
731 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
732 Handle(V3d_View) aView;
734 for (aV3dViewer->InitDefinedViews();
735 aV3dViewer->MoreDefinedViews();
736 aV3dViewer->NextDefinedViews()) {
737 Handle(V3d_View) aV = aV3dViewer->DefinedView();
738 double aS = aV->Scale();
746 double aLen = aView->Convert(20);
748 double aPrevLen = SketcherPrs_Tools::getArrowSize();
749 SketcherPrs_Tools::setArrowSize(aLen);
750 const double aPrevScale = aViewer->Scale(aViewer->activeView());
751 const double aCurScale = aViewer->activeView()->Camera()->Scale();
752 aViewer->SetScale(aViewer->activeView(), aCurScale);
753 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
754 bool isModified = false;
755 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
756 foreach (AISObjectPtr aAIS, aPrsList) {
757 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
759 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
760 if (!aDim.IsNull()) {
761 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
762 aContext->Redisplay(aDim, false);
767 aDisplayer->updateViewer();
770 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature, const ModuleBase_CustomizeFlag& theFlag,
771 const bool theUpdateViewer)
773 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
776 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
777 const bool theUpdateViewer)
779 myCustomPrs->deactivate(theFlag, theUpdateViewer);
782 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
783 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
785 bool aCustomized = false;
790 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
791 XGUI_Workshop* aWorkshop = aConnector->workshop();
792 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
793 ObjectPtr anObject = aDisplayer->getObject(thePrs);
794 if (anObject.get()) {
795 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
796 // customize sketcy symbol presentation
798 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
799 if (!anAISIO.IsNull()) {
800 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
801 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
802 if (!aPrs.IsNull()) {
803 std::vector<int> aColor;
804 myOverconstraintListener->getConflictingColor(aColor);
805 aPrs->SetConflictingConstraint(isConflicting, aColor);
811 // customize sketch dimension constraint presentation
813 std::vector<int> aColor;
815 myOverconstraintListener->getConflictingColor(aColor);
818 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
819 if (!aColor.empty()) {
820 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
829 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
830 const bool theUpdateViewer)
832 bool isRedisplayed = false;
833 if (myCustomPrs->isActive(theFlag))
834 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
836 return isRedisplayed;
839 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
841 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
843 QLabel* aLabel = aOB->activeDocLabel();
844 aLabel->installEventFilter(myMenuMgr);
845 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
846 SLOT(onActiveDocPopup(const QPoint&)));
847 //QPalette aPalet = aLabel->palette();
848 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
849 //aLabel->setPalette(aPalet);
850 aOB->treeView()->setExpandsOnDoubleClick(false);
851 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
852 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
856 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
858 SessionPtr aMgr = ModelAPI_Session::get();
859 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
861 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
862 XGUI_Workshop* aWorkshop = aConnector->workshop();
863 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
865 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
868 aMenu.addAction(aActivatePartAction);
869 aMenu.exec(aHeader->mapToGlobal(thePnt));
873 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
876 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
878 /// If last line finished on vertex the lines creation sequence has to be break
879 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
881 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
882 // if there is an active widget, find the presented object in it
884 anActiveWidget = aPanel->preselectionWidget();
886 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
888 if (aWidgetValidated)
889 anObject = aWidgetValidated->findPresentedObject(theAIS);
895 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
897 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
898 int aSelected = aObjects.size();
899 SessionPtr aMgr = ModelAPI_Session::get();
900 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
902 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
903 if (aSelected == 1) {
904 bool hasResult = false;
905 bool hasFeature = false;
906 bool hasParameter = false;
907 bool hasSubFeature = false;
908 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
910 ObjectPtr aObject = aObjects.first();
912 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
913 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
914 bool isPart = aPart.get() ||
915 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
917 DocumentPtr aPartDoc;
919 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
921 if (aPart.get()) // this may be null is Part feature is disabled
922 aPartDoc = aPart->partDoc();
924 theMenu->addAction(aActivatePartAction);
925 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
927 } else if (aObject->document() == aMgr->activeDocument()) {
928 if (hasParameter || hasFeature) {
929 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
930 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
931 if (aCurrentOp && aFeature.get()) {
932 if (aCurrentOp->id().toStdString() == aFeature->getKind())
933 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
938 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
940 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
943 bool aNotDeactivate = (aCurrentOp == 0);
944 if (!aNotDeactivate) {
945 aActivatePartAction->setEnabled(false);
949 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
951 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
952 // Do not change activation of parts if an operation active
953 static QStringList aAllowActivationList;
954 if (aAllowActivationList.isEmpty())
955 aAllowActivationList <<
956 QString(PartSetPlugin_Part::ID().c_str()) <<
957 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
958 QString(PartSetPlugin_Remove::ID().c_str());
959 if (myWorkshop->currentOperation() &&
960 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
962 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
963 XGUI_Workshop* aWorkshop = aConnector->workshop();
964 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
965 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
966 QPalette aPalet = aLabel->palette();
968 SessionPtr aMgr = ModelAPI_Session::get();
969 DocumentPtr aActiveDoc = aMgr->activeDocument();
970 if (aActivePartIndex.isValid())
971 aTreeView->setExpanded(aActivePartIndex, false);
972 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
973 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
974 if (aActivePartIndex.isValid())
975 aTreeView->setExpanded(aActivePartIndex, true);
977 aLabel->setPalette(aPalet);
978 aWorkshop->updateCommandStatus();
980 // Update displayed objects in order to update active color
981 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
982 QObjectPtrList aObjects = aDisplayer->displayedObjects();
984 foreach(ObjectPtr aObj, aObjects) {
985 //TODO: replace by redisplay event.
986 aHidden = !aObj->data() || !aObj->data()->isValid() ||
987 aObj->isDisabled() || (!aObj->isDisplayed());
989 aDisplayer->redisplay(aObj, false);
991 aDisplayer->updateViewer();
995 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
997 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
999 SessionPtr aMgr = ModelAPI_Session::get();
1000 if (!theIndex.isValid()) {
1001 aMgr->setActiveDocument(aMgr->moduleDocument());
1004 if (theIndex.column() != 0) // Use only first column
1007 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1008 XGUI_Workshop* aWorkshop = aConnector->workshop();
1009 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1010 // De not use non editable Indexes
1011 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1013 ObjectPtr aObj = aDataModel->object(theIndex);
1015 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1016 if (!aPart.get()) { // Probably this is Feature
1017 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1018 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1019 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1022 if (aPart.get()) { // if this is a part
1023 if (aPart->partDoc() == aMgr->activeDocument()) {
1024 myMenuMgr->activatePartSet();
1032 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1034 // z layer is created for all started operations in order to visualize operation AIS presentation
1036 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1037 if (aContext.IsNull())
1040 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1041 if (myVisualLayerId == 0) {
1042 if (myVisualLayerId == 0)
1043 aViewer->AddZLayer(myVisualLayerId);
1045 TColStd_SequenceOfInteger aZList;
1046 aViewer->GetAllZLayers(aZList);
1047 bool aFound = false;
1048 for (int i = 1; i <= aZList.Length(); i++) {
1049 if (aZList(i) == myVisualLayerId) {
1055 aViewer->AddZLayer(myVisualLayerId);
1057 // if there is an active operation with validated widget,
1058 // the filters of this widget should be activated in the created view
1059 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1061 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1062 if (anActiveWidget) {
1063 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1065 aWSelector->activateSelectionAndFilters(true);
1070 //******************************************************
1071 void PartSet_Module::widgetStateChanged(int thePreviousState)
1073 mySketchMgr->widgetStateChanged(thePreviousState);
1076 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1078 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1081 //******************************************************
1082 void PartSet_Module::beforeOperationStarted(ModuleBase_Operation* theOperation)
1086 //******************************************************
1087 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1089 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1090 mySketchMgr->stopSketch(theOperation);
1094 //******************************************************
1095 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1097 GeomShapePtr aGeomShape;
1099 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1100 if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1101 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1106 //******************************************************
1107 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1108 const GeomShapePtr& theGeomShape)
1110 AttributePtr anAttribute;
1111 GeomShapePtr aGeomShape = theGeomShape;
1112 if (!aGeomShape.get()) {
1113 // processing shape of result, e.g. sketch circle center is selected, this is a result
1114 // the geom shape is empty, the shape of result should be used
1115 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1116 if (aResult.get()) {
1117 aGeomShape = aResult->shape();
1121 if (aGeomShape.get()) {
1122 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1123 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1124 mySketchMgr->activeSketch());
1129 //******************************************************
1130 void PartSet_Module::getColor(const ObjectPtr& theObject, std::vector<int>& theColor)
1132 if (myOverconstraintListener->isConflictingObject(theObject)) {
1133 myOverconstraintListener->getConflictingColor(theColor);
1137 //******************************************************
1138 void PartSet_Module::onBooleanOperationChange(int theOperation)
1140 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1143 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1144 switch (theOperation) {
1146 aPanel->setWindowTitle(tr("Cut"));
1149 aPanel->setWindowTitle(tr("Fuse"));
1152 aPanel->setWindowTitle(tr("Common"));