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_PreviewPlanes.h"
8 #include "PartSet_WidgetPoint2d.h"
9 #include "PartSet_WidgetPoint2dDistance.h"
10 #include "PartSet_WidgetPoint2DFlyout.h"
11 #include "PartSet_WidgetShapeSelector.h"
12 #include "PartSet_WidgetMultiSelector.h"
13 #include "PartSet_WidgetEditor.h"
14 #include "PartSet_WidgetFileSelector.h"
15 #include "PartSet_WidgetSketchCreator.h"
16 #include "PartSet_SketcherMgr.h"
17 #include "PartSet_SketcherReetntrantMgr.h"
18 #include "PartSet_ResultSketchPrs.h"
19 #include "PartSet_MenuMgr.h"
20 #include "PartSet_CustomPrs.h"
21 #include "PartSet_IconFactory.h"
22 #include "PartSet_WidgetChoice.h"
23 #include "PartSet_OverconstraintListener.h"
25 #include "PartSet_Filters.h"
26 #include "PartSet_FilterInfinite.h"
28 #include <PartSetPlugin_Remove.h>
29 #include <PartSetPlugin_Part.h>
30 #include <PartSetPlugin_Duplicate.h>
32 #include <ModuleBase_Operation.h>
33 #include <ModuleBase_OperationAction.h>
34 #include <ModuleBase_IViewer.h>
35 #include <ModuleBase_IViewWindow.h>
36 #include <ModuleBase_IPropertyPanel.h>
37 #include <ModuleBase_WidgetEditor.h>
38 #include <ModuleBase_WidgetValidated.h>
39 #include <ModuleBase_FilterFactory.h>
40 #include <ModuleBase_Tools.h>
41 #include <ModuleBase_OperationFeature.h>
42 #include <ModuleBase_WidgetFactory.h>
43 #include <ModuleBase_OperationDescription.h>
44 #include <ModuleBase_ViewerPrs.h>
46 #include <ModelAPI_Object.h>
47 #include <ModelAPI_Events.h>
48 #include <ModelAPI_Validator.h>
49 #include <ModelAPI_Data.h>
50 #include <ModelAPI_Session.h>
51 #include <ModelAPI_ResultBody.h>
52 #include <ModelAPI_AttributeString.h>
53 #include <ModelAPI_AttributeSelectionList.h>
54 #include <ModelAPI_Tools.h>
56 #include <GeomDataAPI_Point2D.h>
57 #include <GeomDataAPI_Point.h>
58 #include <GeomDataAPI_Dir.h>
60 #include <XGUI_Displayer.h>
61 #include <XGUI_Workshop.h>
62 #include <XGUI_OperationMgr.h>
63 #include <XGUI_PropertyPanel.h>
64 #include <XGUI_ModuleConnector.h>
65 #include <XGUI_ContextMenuMgr.h>
66 #include <XGUI_Tools.h>
67 #include <XGUI_ObjectsBrowser.h>
68 #include <XGUI_SelectionMgr.h>
69 #include <XGUI_DataModel.h>
70 #include <XGUI_ErrorMgr.h>
71 #include <XGUI_CustomPrs.h>
72 #include <XGUI_SelectionMgr.h>
73 #include <XGUI_ActionsMgr.h>
75 #include <SketchPlugin_Feature.h>
76 #include <SketchPlugin_Sketch.h>
77 #include <SketchPlugin_ConstraintAngle.h>
78 #include <SketchPlugin_ConstraintLength.h>
79 #include <SketchPlugin_ConstraintDistance.h>
80 #include <SketchPlugin_ConstraintParallel.h>
81 #include <SketchPlugin_ConstraintPerpendicular.h>
82 #include <SketchPlugin_ConstraintRadius.h>
84 #include <SketcherPrs_SymbolPrs.h>
85 #include <SketcherPrs_Coincident.h>
86 #include <SketcherPrs_Tools.h>
88 #include <Events_Loop.h>
89 #include <Config_PropManager.h>
90 #include <Config_Keywords.h>
92 #include <StdSelect_TypeOfFace.hxx>
93 #include <TopoDS_Vertex.hxx>
95 #include <TopoDS_Shape.hxx>
96 #include <BRep_Tool.hxx>
97 #include <AIS_Dimension.hxx>
100 #include <QMouseEvent>
103 #include <QApplication>
104 #include <QMessageBox>
105 #include <QMainWindow>
109 #include <GeomAlgoAPI_FaceBuilder.h>
110 #include <GeomDataAPI_Dir.h>
112 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
118 /*!Create and return new instance of XGUI_Module*/
119 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
121 return new PartSet_Module(theWshop);
124 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
125 : ModuleBase_IModule(theWshop),
128 new PartSet_IconFactory();
130 mySketchMgr = new PartSet_SketcherMgr(this);
131 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
133 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
134 XGUI_Workshop* aWorkshop = aConnector->workshop();
136 ModuleBase_IViewer* aViewer = theWshop->viewer();
137 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
138 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
139 connect(aViewer, SIGNAL(viewTransformed(int)),
140 SLOT(onViewTransformed(int)));
141 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
142 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
143 myMenuMgr = new PartSet_MenuMgr(this);
144 myCustomPrs = new PartSet_CustomPrs(theWshop);
146 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
148 Events_Loop* aLoop = Events_Loop::loop();
149 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
151 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
152 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
154 setDefaultConstraintShown();
156 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
157 "Reference shape wireframe color in operation", Config_Prop::Color,
158 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
159 Config_PropManager::registerProp("Visualization", "operation_result_color",
160 "Result shape wireframe color in operation", Config_Prop::Color,
161 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
162 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
163 "Multi selector item color in operation", Config_Prop::Color,
164 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
167 PartSet_Module::~PartSet_Module()
169 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
170 for (; aIt.More(); aIt.Next()) {
171 Handle(SelectMgr_Filter) aFilter = aIt.Value();
172 if (!aFilter.IsNull())
176 delete myOverconstraintListener;
179 void PartSet_Module::activateSelectionFilters()
181 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
182 for (; aIt.More(); aIt.Next()) {
183 Handle(SelectMgr_Filter) aFilter = aIt.Value();
184 if (!aFilter.IsNull())
185 myWorkshop->viewer()->addSelectionFilter(aFilter);
189 void PartSet_Module::deactivateSelectionFilters()
191 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
192 for (; aIt.More(); aIt.Next()) {
193 Handle(SelectMgr_Filter) aFilter = aIt.Value();
194 if (!aFilter.IsNull())
195 myWorkshop->viewer()->removeSelectionFilter(aFilter);
199 void PartSet_Module::storeSelection()
201 sketchMgr()->storeSelection();
204 void PartSet_Module::restoreSelection()
206 sketchMgr()->restoreSelection();
209 void PartSet_Module::registerValidators()
211 //Registering of validators
212 SessionPtr aMgr = ModelAPI_Session::get();
213 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
214 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
215 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
216 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
217 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
218 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
219 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
220 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
221 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
222 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
223 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
224 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
225 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
226 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
227 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
228 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
229 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
232 void PartSet_Module::registerFilters()
234 //Registering of selection filters
235 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
236 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
239 void PartSet_Module::registerProperties()
241 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
243 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
244 Config_Prop::Integer, SKETCH_WIDTH);
245 Config_PropManager::registerProp("Sketch planes", "rotate_to_plane", "Rotate to plane when selected",
246 Config_Prop::Boolean, "false");
249 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
251 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
254 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
256 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
257 mySketchMgr->commitNestedSketch(theOperation);
260 /// Restart sketcher operations automatically
261 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
263 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
264 if (aFOperation && !aFOperation->isEditOperation()) {
265 // the selection is cleared after commit the create operation
266 // in order to do not use the same selected objects in the restarted operation
267 // for common behaviour, the selection is cleared even if the operation is not restarted
268 getWorkshop()->selector()->clearSelection();
273 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
275 /// Restart sketcher operations automatically
276 mySketchReentrantMgr->operationAborted(theOperation);
279 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
281 ModuleBase_IWorkshop* anIWorkshop = workshop();
282 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
283 anIWorkshop->updateCommandStatus();
286 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
289 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(anIWorkshop);
290 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
291 ModuleBase_ModelWidget* aFilledWidget = 0;
292 bool aPostonedWidgetActivation = false;
293 FeaturePtr aFeature = aFOperation->feature();
295 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(anIWorkshop, aFeature);
296 // if there is a greed attribute, automatic commit by preselection for this feature is prohibited
297 aWorkshop->setPropertyPanel(aFOperation);
299 // filling the operation values by the current selection
300 // if the operation can be committed after the controls filling, the method perform should
301 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
302 bool isOperationCommitted = false;
303 if (!aFOperation->isEditOperation()) {
304 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
305 if (currentOperation() != aFOperation)
306 isOperationCommitted = true;
308 if (aGreedAttributeId.empty()) {
309 // a signal should be emitted before the next widget activation
310 // because, the activation of the next widget will give a focus to the widget. As a result
311 // the value of the widget is initialized. And commit may happens until the value is entered.
313 if (mySketchReentrantMgr->canBeCommittedByPreselection())
314 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
315 // activate the next obligatory widget
316 if (!isOperationCommitted)
317 aPropertyPanel->activateNextWidget(aFilledWidget);
320 else { // there is a greed widget
321 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
322 std::string aFirstAttributeId = aWidgets.front()->attributeID();
323 // activate next widget after greeded if it is the first widget in the panel
324 // else the first panel widget is already activated by operation start
325 if (aFirstAttributeId == aGreedAttributeId)
326 aPostonedWidgetActivation = true;
329 } if (!isOperationCommitted) {
330 anIWorkshop->updateCommandStatus();
331 aWorkshop->connectToPropertyPanel(true);
332 operationStartedInternal(aFOperation);
334 // the objects of the current operation should be deactivated
335 QObjectPtrList anObjects;
336 anObjects.append(aFeature);
337 std::list<ResultPtr> aResults;
338 ModelAPI_Tools::allResults(aFeature, aResults);
339 std::list<ResultPtr>::const_iterator aIt;
340 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
341 anObjects.append(*aIt);
343 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
344 for (; anIt != aLast; anIt++)
345 aWorkshop->deactivateActiveObject(*anIt, false);
346 if (anObjects.size() > 0) {
347 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
348 aDisplayer->updateViewer();
351 if (aPostonedWidgetActivation) {
352 // if the widget is an empty in the chain of activated widgets, the current operation
353 // is restarted. It should be performed after functionality of the operation starting
354 aPropertyPanel->activateNextWidget(aFilledWidget);
360 void PartSet_Module::operationStartedInternal(ModuleBase_Operation* theOperation)
362 /// Restart sketcher operations automatically
363 mySketchReentrantMgr->operationStarted(theOperation);
365 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
366 mySketchMgr->startSketch(theOperation);
368 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
369 mySketchMgr->startNestedSketch(theOperation);
372 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
374 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
375 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
379 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
381 ModuleBase_IModule::operationResumed(theOperation);
383 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
385 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
386 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
390 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
392 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
393 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
394 bool isModified = isModifiedArgs || isModifiedResults;
396 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
397 mySketchMgr->stopNestedSketch(theOperation);
399 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
400 setDefaultConstraintShown();
402 //VSV: Viewer is updated on feature update and redisplay
404 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
405 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
406 aDisplayer->updateViewer();
409 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
410 aLast = myHasConstraintShown.end();
411 for (; anIt != aLast; anIt++) {
412 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
416 ModuleBase_Operation* PartSet_Module::currentOperation() const
418 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
419 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
420 return anOpMgr->currentOperation();
423 bool PartSet_Module::canUndo() const
425 bool aCanUndo = false;
426 SessionPtr aMgr = ModelAPI_Session::get();
427 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
428 aCanUndo = !aMgr->isOperation();
429 if (!aCanUndo) // check the enable state additionally by sketch manager
430 aCanUndo = aMgr->canUndo();
435 bool PartSet_Module::canRedo() const
437 bool aCanRedo = false;
438 SessionPtr aMgr = ModelAPI_Session::get();
439 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
440 aCanRedo = !aMgr->isOperation();
441 if (!aCanRedo) // check the enable state additionally by sketch manager
442 aCanRedo = aMgr->canRedo();
447 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
450 if (theActionId == "MOVE_CMD") {
451 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
453 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
454 // part features can not be moved in the history.
455 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
462 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
464 // the sketch manager put the restriction to the objects erase
465 return mySketchMgr->canEraseObject(theObject);
468 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
470 // the sketch manager put the restriction to the objects display
471 return mySketchMgr->canDisplayObject(theObject);
474 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
476 mySketchMgr->processHiddenObject(theObjects);
479 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
481 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
483 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
484 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
485 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
486 if (isSketchOp || isNestedOp) {
487 // in active sketch operation it is possible to activate operation object in selection
488 // in the edit operation, e.g. points of the line can be moved when the line is edited
489 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
490 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
495 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
497 QMap<int, QAction*>& theMenuActions) const
499 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
502 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
504 myMenuMgr->updateViewerMenu(theStdActions);
507 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
509 bool isEnabledFixed = false;
510 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
511 mySketchReentrantMgr->isInternalEditStarted())
512 isEnabledFixed = true;
513 return isEnabledFixed;
516 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
518 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
519 if (anError.isEmpty())
520 anError = sketchMgr()->getFeatureError(theFeature);
525 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
526 QStringList& theIds) const
528 myMenuMgr->grantedOperationIds(theOperation, theIds);
530 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
531 XGUI_Workshop* aWorkshop = getWorkshop();
532 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
536 void PartSet_Module::activeSelectionModes(QIntList& theModes)
539 if (mySketchMgr->activeSketch().get())
540 PartSet_SketcherMgr::sketchSelectionModes(theModes);
543 void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
545 if (theTypes.contains(TopAbs_FACE))
546 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
547 if (theTypes.contains(TopAbs_WIRE))
548 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
551 bool PartSet_Module::isMouseOverWindow()
553 return mySketchMgr->isMouseOverWindow();
556 void PartSet_Module::closeDocument()
561 void PartSet_Module::clearViewer()
563 myCustomPrs->clearPrs();
565 XGUI_Workshop* aWorkshop = getWorkshop();
566 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
567 aDisplayer->deactivateSelectionFilters();
570 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
572 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
576 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
577 // we have to manually activate the sketch label in edit mode
578 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
579 aPanel->activateWidget(aPanel->modelWidgets().first());
582 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
583 QList<ModuleBase_ModelWidget*>& theWidgets) const
585 bool aProcessed = false;
587 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
588 XGUI_Workshop* aWorkshop = getWorkshop();
589 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
590 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
591 ModuleBase_ISelection* aSelection = workshop()->selection();
592 // click on a point in sketch leads here with the point is highlighted, not yet selected
593 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
594 if (aPreselection.size() == 1) {
595 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
596 ObjectPtr anObject = aSelectedPrs->object();
598 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
599 FeaturePtr anOpFeature = aFOperation->feature();
600 GeomShapePtr aShape = aSelectedPrs->shape();
601 // click on the digit of dimension constrain comes here with an empty shape, so we need the check
602 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
603 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
604 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
605 mySketchMgr->activeSketch());
606 if (anAttribute.get()) {
607 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
608 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
610 const std::string anAttributeId = anAttribute->id();
611 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
613 theWidgets = aFactory.getModelWidgets();
614 // it is possible that the point does not present in XML definition,
615 // in this case, we assume that it is not processed by this module
616 // e.g. "Intersection point" feature
617 aProcessed = !theWidgets.isEmpty();
625 void PartSet_Module::onSelectionChanged()
627 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
631 bool isSketcherOp = false;
632 // An edit operation is enable only if the current opeation is the sketch operation
633 if (mySketchMgr->activeSketch()) {
634 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
635 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
638 // Editing of constraints can be done on selection
639 ModuleBase_ISelection* aSelect = myWorkshop->selection();
640 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
641 if (aSelected.size() == 1) {
642 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
643 ObjectPtr aObject = aPrs->object();
644 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
646 std::string aId = aFeature->getKind();
647 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
648 (aId == SketchPlugin_ConstraintLength::ID()) ||
649 (aId == SketchPlugin_ConstraintDistance::ID()) ||
650 (aId == SketchPlugin_ConstraintAngle::ID())) {
651 editFeature(aFeature);
658 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
660 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
661 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
662 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
665 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
667 Config_WidgetAPI* theWidgetApi)
669 ModuleBase_IWorkshop* aWorkshop = workshop();
670 XGUI_Workshop* aXUIWorkshop = getWorkshop();
671 ModuleBase_ModelWidget* aWgt = NULL;
672 if (theType == "sketch-start-label") {
673 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
674 theWidgetApi, myHasConstraintShown);
675 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
676 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
677 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
678 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
680 } else if (theType == "sketch-2dpoint_selector") {
681 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
683 aPointWgt->setSketch(mySketchMgr->activeSketch());
684 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
686 }else if (theType == "sketch-2dpoint_flyout_selector") {
687 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
689 aPointWgt->setSketch(mySketchMgr->activeSketch());
690 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
692 } else if (theType == "point2ddistance") {
693 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
694 aWorkshop, theWidgetApi);
695 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
697 } else if (theType == "sketch_shape_selector") {
698 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
699 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
700 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
701 aWgt = aShapeSelectorWgt;
702 } else if (theType == "sketch_multi_selector") {
703 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
704 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
705 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
706 aWgt = aShapeSelectorWgt;
708 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
709 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
710 } else if (theType == "export_file_selector") {
711 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
712 } else if (theType == "sketch_launcher") {
713 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
714 } else if (theType == "module_choice") {
715 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
716 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
717 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
722 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
724 ModuleBase_ModelWidget* anActiveWidget = 0;
726 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
727 if (!anActiveWidget) {
728 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
730 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
731 anActiveWidget = aPanel->activeWidget();
734 return anActiveWidget;
737 bool PartSet_Module::deleteObjects()
739 bool isProcessed = false;
741 XGUI_Workshop* aWorkshop = getWorkshop();
742 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
744 //SessionPtr aMgr = ModelAPI_Session::get();
745 // 1. check whether the delete should be processed in the module
746 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
747 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
748 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
749 if (isSketchOp || isNestedOp) {
751 // 2. find selected presentations
752 // selected objects should be collected before the current operation abort because
753 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
754 ModuleBase_ISelection* aSel = workshop()->selection();
755 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
756 // if there are no selected objects in the viewer, that means that the selection in another
757 // place cased this method. It is necessary to return the false value to understande in above
758 // method that delete is not processed
759 if (aSelectedObj.count() == 0)
762 // avoid delete of the objects, which are not belong to the current sketch
763 // in order to do not delete results of other sketches
764 QObjectPtrList aSketchObjects;
765 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
766 for ( ; anIt != aLast; anIt++) {
767 ObjectPtr anObject = *anIt;
768 if (mySketchMgr->isObjectOfSketch(anObject)) {
769 // sketch feature should be used in this list because workshop deletes features only
770 // results are skipped
771 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
772 aSketchObjects.append(aSketchFeature);
775 // if the selection contains only local selected presentations from other sketches,
776 // the Delete operation should not be done at all
777 if (aSketchObjects.size() == 0)
780 // 3. start operation
781 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
782 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
784 // the active nested sketch operation should be aborted unconditionally
785 // the Delete action should be additionally granted for the Sketch operation
786 // in order to do not abort/commit it
787 if (!anOpMgr->canStartOperation(anOpAction->id()))
788 return true; // the objects are processed but can not be deleted
790 anOpMgr->startOperation(anOpAction);
792 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
793 // the problem is in AIS Dimensions recompute if a line and the dim are removed, line is the first
794 // it causes the AIS recompute, where the base line is null, the result is empty AIS in the viewer
795 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
797 // 4. delete features
798 // sketch feature should be skipped, only sub-features can be removed
799 // when sketch operation is active
800 aWorkshop->deleteFeatures(aSketchObjects);
802 anOpMgr->commitOperation();
807 void PartSet_Module::onFeatureTriggered()
809 // is commented for imp: Unpressing the button of the current action must behave like
810 // a validation if the entity can be created (instead of Cancel, as currently)
811 /*QAction* aCmd = dynamic_cast<QAction*>(sender());
812 if (aCmd->isCheckable() && aCmd->isChecked()) {
813 // 1. check whether the delete should be processed in the module
814 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
815 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
817 // in case if in the viewer nothing is displayed, the create operation should not be
818 // comitted even if all values of the feature are initialized
819 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
820 // the action information should be saved before the operation is aborted
821 // because this abort leads to update command status, which unchecks this action
822 anOperation->abort();
823 launchOperation(aCmd->data().toString());
827 ModuleBase_IModule::onFeatureTriggered();
830 void PartSet_Module::editFeature(FeaturePtr theFeature)
832 storeConstraintsState(theFeature->getKind());
833 ModuleBase_IModule::editFeature(theFeature);
836 bool PartSet_Module::canCommitOperation() const
841 void PartSet_Module::launchOperation(const QString& theCmdId,
842 const bool isUpdatePropertyPanel)
844 storeConstraintsState(theCmdId.toStdString());
845 updateConstraintsState(theCmdId.toStdString());
847 ModuleBase_IModule::launchOperation(theCmdId, isUpdatePropertyPanel);
850 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
852 if (myWorkshop->currentOperation() &&
853 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
854 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
855 mySketchMgr->showConstraintStates();
856 myHasConstraintShown = aShownStates;
860 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
862 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str())) {
863 // Show constraints if a constraint was anOperation
864 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
865 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
866 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
867 myHasConstraintShown[PartSet_Tools::Expressions]);
871 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
873 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
874 if (!anAIS.IsNull()) {
875 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
876 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
877 if (!aDim.IsNull()) {
878 aCtx->SetZLayer(aDim, myVisualLayerId);
880 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
882 aCtx->SetZLayer(aCons, myVisualLayerId);
887 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
890 // it should be recomputed in order to disappear in the viewer if the corresponded object
892 //if (myCustomPrs->isActive())
893 // myCustomPrs->redisplay(theObject, false);
896 void PartSet_Module::onViewTransformed(int theTrsfType)
898 // Set length of arrows constant in pixel size
899 // if the operation is panning or rotate or panglobal then do nothing
900 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
902 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
903 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
904 if (aContext.IsNull())
907 //Handle(V3d_View) aView = aViewer->activeView();
909 XGUI_Workshop* aWorkshop = getWorkshop();
910 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
911 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
912 Handle(V3d_View) aView;
914 for (aV3dViewer->InitDefinedViews();
915 aV3dViewer->MoreDefinedViews();
916 aV3dViewer->NextDefinedViews()) {
917 Handle(V3d_View) aV = aV3dViewer->DefinedView();
918 double aS = aV->Scale();
926 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
928 double aPrevLen = SketcherPrs_Tools::getArrowSize();
929 SketcherPrs_Tools::setArrowSize(aLen);
930 const double aPrevScale = aViewer->Scale(aViewer->activeView());
931 const double aCurScale = aViewer->activeView()->Camera()->Scale();
932 aViewer->SetScale(aViewer->activeView(), aCurScale);
933 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
934 bool isModified = false;
935 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
936 foreach (AISObjectPtr aAIS, aPrsList) {
937 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
939 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
940 if (!aDim.IsNull()) {
941 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
942 aContext->Redisplay(aDim, false);
947 aDisplayer->updateViewer();
950 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature, const ModuleBase_CustomizeFlag& theFlag,
951 const bool theUpdateViewer)
953 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
956 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
957 const bool theUpdateViewer)
959 myCustomPrs->deactivate(theFlag, theUpdateViewer);
962 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
963 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
965 bool aCustomized = false;
967 XGUI_Workshop* aWorkshop = getWorkshop();
968 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
969 ObjectPtr anObject = aDisplayer->getObject(thePrs);
973 if (!theResult.get()) {
974 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
975 // customize sketch symbol presentation
977 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
978 if (!anAISIO.IsNull()) {
979 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
980 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
981 if (!aPrs.IsNull()) {
982 std::vector<int> aColor;
983 myOverconstraintListener->getConflictingColor(aColor);
984 aPrs->SetConflictingConstraint(isConflicting, aColor);
987 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
988 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
989 if (!aPrs.IsNull()) {
990 std::vector<int> aColor;
991 myOverconstraintListener->getConflictingColor(aColor);
992 aPrs->SetConflictingConstraint(isConflicting, aColor);
998 // customize sketch dimension constraint presentation
1000 std::vector<int> aColor;
1001 if (isConflicting) {
1002 myOverconstraintListener->getConflictingColor(aColor);
1005 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1006 if (!aColor.empty()) {
1007 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1011 // customize dimentional constrains
1012 sketchMgr()->customizePresentation(anObject);
1017 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1018 const bool theUpdateViewer)
1020 bool isRedisplayed = false;
1021 if (myCustomPrs->isActive(theFlag))
1022 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1024 return isRedisplayed;
1027 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1029 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1031 QLabel* aLabel = aOB->activeDocLabel();
1032 aLabel->installEventFilter(myMenuMgr);
1033 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1034 SLOT(onActiveDocPopup(const QPoint&)));
1035 //QPalette aPalet = aLabel->palette();
1036 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
1037 //aLabel->setPalette(aPalet);
1038 aOB->treeView()->setExpandsOnDoubleClick(false);
1039 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1040 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1044 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1046 SessionPtr aMgr = ModelAPI_Session::get();
1047 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1049 XGUI_Workshop* aWorkshop = getWorkshop();
1050 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1052 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1055 aMenu.addAction(aActivatePartAction);
1056 aMenu.exec(aHeader->mapToGlobal(thePnt));
1059 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1061 return mySketchMgr->createPresentation(theResult);
1065 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1068 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1070 /// If last line finished on vertex the lines creation sequence has to be break
1071 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1073 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1074 // if there is an active widget, find the presented object in it
1075 if (!anActiveWidget)
1076 anActiveWidget = aPanel->preselectionWidget();
1078 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1080 if (aWidgetValidated)
1081 anObject = aWidgetValidated->findPresentedObject(theAIS);
1087 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1089 bool aCanBeShaged = true;
1091 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1093 aCanBeShaged = false;
1095 return aCanBeShaged;
1098 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1100 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1101 int aSelected = aObjects.size();
1102 SessionPtr aMgr = ModelAPI_Session::get();
1103 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1105 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1106 if (aSelected == 1) {
1107 bool hasResult = false;
1108 bool hasFeature = false;
1109 bool hasParameter = false;
1110 bool hasCompositeOwner = false;
1111 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1113 ObjectPtr aObject = aObjects.first();
1115 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1116 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1117 bool isPart = aPart.get() ||
1118 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1120 DocumentPtr aPartDoc;
1122 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1124 if (aPart.get()) // this may be null is Part feature is disabled
1125 aPartDoc = aPart->partDoc();
1127 theMenu->addAction(aActivatePartAction);
1128 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1130 } else if (aObject->document() == aMgr->activeDocument()) {
1131 if (hasParameter || hasFeature) {
1132 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1133 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1134 if (aCurrentOp && aFeature.get()) {
1135 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1136 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1141 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1143 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
1146 bool aNotDeactivate = (aCurrentOp == 0);
1147 if (!aNotDeactivate) {
1148 aActivatePartAction->setEnabled(false);
1152 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1154 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1155 // Do not change activation of parts if an operation active
1156 static QStringList aAllowActivationList;
1157 if (aAllowActivationList.isEmpty())
1158 aAllowActivationList <<
1159 QString(PartSetPlugin_Part::ID().c_str()) <<
1160 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1161 QString(PartSetPlugin_Remove::ID().c_str());
1162 if (myWorkshop->currentOperation() &&
1163 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1165 XGUI_Workshop* aWorkshop = getWorkshop();
1166 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1167 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1168 QPalette aPalet = aLabel->palette();
1170 SessionPtr aMgr = ModelAPI_Session::get();
1171 DocumentPtr aActiveDoc = aMgr->activeDocument();
1172 if (aActivePartIndex.isValid())
1173 aTreeView->setExpanded(aActivePartIndex, false);
1174 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1175 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1176 if (aActivePartIndex.isValid())
1177 aTreeView->setExpanded(aActivePartIndex, true);
1179 aLabel->setPalette(aPalet);
1180 aWorkshop->updateCommandStatus();
1182 // Update displayed objects in order to update active color
1183 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1184 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1186 foreach(ObjectPtr aObj, aObjects) {
1187 //TODO: replace by redisplay event.
1188 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1189 aObj->isDisabled() || (!aObj->isDisplayed());
1191 aDisplayer->redisplay(aObj, false);
1193 aDisplayer->updateViewer();
1197 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1199 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1201 SessionPtr aMgr = ModelAPI_Session::get();
1202 if (!theIndex.isValid()) {
1203 aMgr->setActiveDocument(aMgr->moduleDocument());
1206 if (theIndex.column() != 0) // Use only first column
1209 XGUI_Workshop* aWorkshop = getWorkshop();
1210 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1211 // De not use non editable Indexes
1212 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1214 ObjectPtr aObj = aDataModel->object(theIndex);
1216 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1217 if (!aPart.get()) { // Probably this is Feature
1218 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1219 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1220 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1223 if (aPart.get()) { // if this is a part
1224 if (aPart->partDoc() == aMgr->activeDocument()) {
1225 myMenuMgr->activatePartSet();
1233 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1235 // z layer is created for all started operations in order to visualize operation AIS presentation
1237 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1238 if (aContext.IsNull())
1241 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1242 if (myVisualLayerId == 0) {
1243 if (myVisualLayerId == 0)
1244 aViewer->AddZLayer(myVisualLayerId);
1246 TColStd_SequenceOfInteger aZList;
1247 aViewer->GetAllZLayers(aZList);
1248 bool aFound = false;
1249 for (int i = 1; i <= aZList.Length(); i++) {
1250 if (aZList(i) == myVisualLayerId) {
1256 aViewer->AddZLayer(myVisualLayerId);
1258 // if there is an active operation with validated widget,
1259 // the filters of this widget should be activated in the created view
1260 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1262 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1263 if (anActiveWidget) {
1264 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1266 aWSelector->activateSelectionAndFilters(true);
1271 //******************************************************
1272 void PartSet_Module::widgetStateChanged(int thePreviousState)
1274 mySketchMgr->widgetStateChanged(thePreviousState);
1277 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1279 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1282 //******************************************************
1283 void PartSet_Module::beforeOperationStarted(ModuleBase_Operation* theOperation)
1287 //******************************************************
1288 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1290 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1291 mySketchMgr->stopSketch(theOperation);
1295 //******************************************************
1296 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1298 GeomShapePtr aGeomShape;
1300 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1301 if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1302 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1307 //******************************************************
1308 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1309 const GeomShapePtr& theGeomShape)
1311 AttributePtr anAttribute;
1312 GeomShapePtr aGeomShape = theGeomShape;
1313 if (!aGeomShape.get()) {
1314 // processing shape of result, e.g. sketch circle center is selected, this is a result
1315 // the geom shape is empty, the shape of result should be used
1316 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1317 if (aResult.get()) {
1318 aGeomShape = aResult->shape();
1322 if (aGeomShape.get()) {
1323 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1324 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1325 mySketchMgr->activeSketch());
1330 //******************************************************
1331 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1334 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1338 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1339 if (!aChoiceTitle.isEmpty()) {
1340 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1343 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1345 aPanel->setWindowTitle(aChoiceTitle);
1349 //******************************************************
1350 XGUI_Workshop* PartSet_Module::getWorkshop() const
1352 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1353 return aConnector->workshop();
1356 //******************************************************
1357 void PartSet_Module::setDefaultConstraintShown()
1359 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1360 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1361 myHasConstraintShown[PartSet_Tools::Expressions] = false;