1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_Module.h"
22 #include "PartSet_WidgetSketchLabel.h"
23 #include "PartSet_Validators.h"
24 #include "PartSet_Tools.h"
25 #include "PartSet_PreviewPlanes.h"
26 #include "PartSet_WidgetPoint2d.h"
27 #include "PartSet_WidgetPoint2DFlyout.h"
28 #include "PartSet_WidgetShapeSelector.h"
29 #include "PartSet_WidgetMultiSelector.h"
30 #include "PartSet_WidgetFeaturePointSelector.h"
31 #include "PartSet_WidgetEditor.h"
32 #include "PartSet_WidgetFileSelector.h"
33 #include "PartSet_WidgetSketchCreator.h"
34 #include "PartSet_SketcherMgr.h"
35 #include "PartSet_SketcherReentrantMgr.h"
36 #include "PartSet_ResultSketchPrs.h"
37 #include "PartSet_MenuMgr.h"
38 #include "PartSet_CustomPrs.h"
39 #include "PartSet_IconFactory.h"
40 #include "PartSet_OverconstraintListener.h"
42 #include "PartSet_Filters.h"
43 #include "PartSet_FilterInfinite.h"
45 #include <PartSetPlugin_Remove.h>
46 #include <PartSetPlugin_Part.h>
47 #include <PartSetPlugin_Duplicate.h>
49 #include <ModuleBase_Operation.h>
50 #include <ModuleBase_OperationAction.h>
51 #include <ModuleBase_IViewer.h>
52 #include <ModuleBase_IViewWindow.h>
53 #include <ModuleBase_IPropertyPanel.h>
54 #include <ModuleBase_ISelectionActivate.h>
55 #include <ModuleBase_WidgetChoice.h>
56 #include <ModuleBase_WidgetEditor.h>
57 #include <ModuleBase_WidgetValidated.h>
58 #include <ModuleBase_Tools.h>
59 #include <ModuleBase_OperationFeature.h>
60 #include <ModuleBase_WidgetFactory.h>
61 #include <ModuleBase_OperationDescription.h>
62 #include <ModuleBase_ViewerPrs.h>
64 #include <ModelAPI_Object.h>
65 #include <ModelAPI_Events.h>
66 #include <ModelAPI_Validator.h>
67 #include <ModelAPI_Data.h>
68 #include <ModelAPI_Session.h>
69 #include <ModelAPI_ResultBody.h>
70 #include <ModelAPI_AttributeString.h>
71 #include <ModelAPI_AttributeSelectionList.h>
72 #include <ModelAPI_Tools.h>
73 #include <ModelAPI_ResultConstruction.h>
75 #include <GeomDataAPI_Point2D.h>
76 #include <GeomDataAPI_Point.h>
77 #include <GeomDataAPI_Dir.h>
79 #include <XGUI_ActiveControlMgr.h>
80 #include <XGUI_ActiveControlSelector.h>
81 #include <XGUI_ActionsMgr.h>
82 #include <XGUI_ContextMenuMgr.h>
83 #include <XGUI_CustomPrs.h>
84 #include <XGUI_DataModel.h>
85 #include <XGUI_Displayer.h>
86 #include <XGUI_ErrorMgr.h>
87 #include <XGUI_FacesPanelSelector.h>
88 #include <XGUI_ModuleConnector.h>
89 #include <XGUI_ObjectsBrowser.h>
90 #include <XGUI_OperationMgr.h>
91 #include <XGUI_PropertyPanel.h>
92 #include <XGUI_SelectionMgr.h>
93 #include <XGUI_Tools.h>
94 #include <XGUI_Workshop.h>
96 #include <SketchPlugin_ConstraintAngle.h>
97 #include <SketchPlugin_ConstraintLength.h>
98 #include <SketchPlugin_ConstraintDistance.h>
99 #include <SketchPlugin_ConstraintParallel.h>
100 #include <SketchPlugin_ConstraintPerpendicular.h>
101 #include <SketchPlugin_ConstraintRadius.h>
102 #include <SketchPlugin_Feature.h>
103 #include <SketchPlugin_Projection.h>
104 #include <SketchPlugin_Sketch.h>
106 #include <SketcherPrs_SymbolPrs.h>
107 #include <SketcherPrs_Coincident.h>
108 #include <SketcherPrs_Tools.h>
110 #include <Events_Loop.h>
111 #include <Config_PropManager.h>
112 #include <Config_Keywords.h>
114 #include <AIS_Dimension.hxx>
115 #include <AIS_InteractiveObject.hxx>
116 #include <StdSelect_TypeOfFace.hxx>
117 #include <TopoDS_Vertex.hxx>
118 #include <TopoDS.hxx>
119 #include <TopoDS_Shape.hxx>
120 #include <BRep_Tool.hxx>
123 #include <QMouseEvent>
126 #include <QApplication>
127 #include <QMessageBox>
128 #include <QMainWindow>
132 #include <GeomAlgoAPI_FaceBuilder.h>
133 #include <GeomDataAPI_Dir.h>
135 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
141 /*!Create and return new instance of XGUI_Module*/
142 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
144 return new PartSet_Module(theWshop);
147 //******************************************************
148 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
149 : ModuleBase_IModule(theWshop),
151 myIsOperationIsLaunched(false)
153 new PartSet_IconFactory();
155 mySketchMgr = new PartSet_SketcherMgr(this);
156 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
158 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
159 XGUI_Workshop* aWorkshop = aConnector->workshop();
161 ModuleBase_IViewer* aViewer = theWshop->viewer();
162 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
163 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
164 connect(aViewer, SIGNAL(viewTransformed(int)),
165 SLOT(onViewTransformed(int)));
166 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
167 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
168 myMenuMgr = new PartSet_MenuMgr(this);
169 myCustomPrs = new PartSet_CustomPrs(theWshop);
171 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
173 Events_Loop* aLoop = Events_Loop::loop();
174 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
176 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
177 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
179 setDefaultConstraintShown();
181 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
182 "Reference shape wireframe color in operation", Config_Prop::Color,
183 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
184 Config_PropManager::registerProp("Visualization", "operation_result_color",
185 "Result shape wireframe color in operation", Config_Prop::Color,
186 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
187 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
188 "Multi selector item color in operation", Config_Prop::Color,
189 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
190 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
191 "Color of removed feature in operation", Config_Prop::Color,
192 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
193 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
194 "Color of sketch plane", Config_Prop::Color,
195 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
197 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
198 "Hidden faces transparency",
203 //******************************************************
204 PartSet_Module::~PartSet_Module()
206 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
207 for (; aIt.More(); aIt.Next()) {
208 Handle(SelectMgr_Filter) aFilter = aIt.Value();
209 if (!aFilter.IsNull())
213 delete myOverconstraintListener;
216 //******************************************************
217 void PartSet_Module::storeSelection()
219 // cash is used only to restore selection, so it should be filled in storeSelection and
220 // after applying immediatelly cleared in restoreSelection
221 myCurrentSelection.clear();
222 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
225 //******************************************************
226 void PartSet_Module::restoreSelection()
228 // cash is used only to restore selection, so it should be filled in storeSelection and
229 // after applying immediatelly cleared in restoreSelection
230 sketchMgr()->restoreSelection(myCurrentSelection);
231 myCurrentSelection.clear();
234 //******************************************************
235 void PartSet_Module::registerValidators()
237 //Registering of validators
238 SessionPtr aMgr = ModelAPI_Session::get();
239 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
240 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
241 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
242 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
243 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
244 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
245 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
246 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
247 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
248 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
249 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
250 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
251 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
252 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
253 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
254 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
255 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
256 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
257 aFactory->registerValidator("PartSet_MultyTranslationSelection",
258 new PartSet_MultyTranslationSelection);
259 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
260 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
263 //******************************************************
264 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
265 const bool isToConnect)
267 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
270 //******************************************************
271 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
273 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
274 mySketchMgr->commitNestedSketch(theOperation);
276 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
277 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
278 overconstraintListener()->setActive(false);
280 /// Restart sketcher operations automatically
281 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
283 ModuleBase_OperationFeature* aFOperation =
284 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
285 if (aFOperation && !aFOperation->isEditOperation()) {
286 // the selection is cleared after commit the create operation
287 // in order to do not use the same selected objects in the restarted operation
288 // for common behaviour, the selection is cleared even if the operation is not restarted
289 getWorkshop()->selector()->clearSelection();
294 //******************************************************
295 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
297 /// Restart sketcher operations automatically
298 mySketchReentrantMgr->operationAborted(theOperation);
299 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
300 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
301 overconstraintListener()->setActive(false);
304 //******************************************************
305 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
307 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
310 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
311 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
313 ModuleBase_ModelWidget* aFilledWidget = 0;
314 bool aPostonedWidgetActivation = false;
316 FeaturePtr aFeature = aFOperation->feature();
317 /// Restart sketcher operations automatically
318 /// it is important to call method of sketch reentrant manager before filling of PP
319 /// because it fills some created feature attributes, these new values should be used
320 /// to fill the property panel
321 mySketchReentrantMgr->operationStarted(theOperation);
323 aWorkshop->fillPropertyPanel(aFOperation);
324 // filling the operation values by the current selection
325 // if the operation can be committed after the controls filling, the method perform should
326 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
327 bool isOperationCommitted = false;
328 if (!aFOperation->isEditOperation()) {
329 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
330 // if there is a greed attribute, automatic commit by preselection
331 // for this feature is prohibited
332 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
333 if (currentOperation() != aFOperation)
334 isOperationCommitted = true;
336 if (aGreedAttributeId.empty()) {
337 // a signal should be emitted before the next widget activation
338 // because, the activation of the next widget will give a focus to the widget.
339 // As a result the value of the widget is initialized.
340 // And commit may happens until the value is entered.
342 if (mySketchReentrantMgr->canBeCommittedByPreselection())
343 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
344 // activate the next obligatory widget
345 if (!isOperationCommitted)
346 aPropertyPanel->activateNextWidget(aFilledWidget);
349 else { // there is a greed widget
350 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
351 std::string aFirstAttributeId = aWidgets.front()->attributeID();
352 // activate next widget after greeded if it is the first widget in the panel
353 // else the first panel widget is already activated by operation start
354 if (aFirstAttributeId == aGreedAttributeId)
355 aPostonedWidgetActivation = true;
358 } if (!isOperationCommitted) {
359 aWorkshop->connectToPropertyPanel(true);
360 updateSketcherOnStart(aFOperation);
361 updatePresentationsOnStart(aFOperation);
363 // the objects of the current operation should be deactivated
364 QObjectPtrList anObjects;
365 anObjects.append(aFeature);
366 std::list<ResultPtr> aResults;
367 ModelAPI_Tools::allResults(aFeature, aResults);
368 std::list<ResultPtr>::const_iterator aIt;
369 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
370 anObjects.append(*aIt);
372 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
373 for (; anIt != aLast; anIt++)
374 aWorkshop->deactivateActiveObject(*anIt, false);
375 if (anObjects.size() > 0) {
376 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
377 aDisplayer->updateViewer();
379 /// state of command actions should be updated after displayed objects modification because
380 /// deactivation(for example) of objects may influence on selection in the viewer
381 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
382 workshop()->updateCommandStatus();
384 if (aPostonedWidgetActivation) {
385 // if the widget is an empty in the chain of activated widgets, the current operation
386 // is restarted. It should be performed after functionality of the operation starting
387 aPropertyPanel->activateNextWidget(aFilledWidget);
392 //******************************************************
393 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
395 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
396 mySketchMgr->startSketch(theOperation);
398 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
399 mySketchMgr->startNestedSketch(theOperation);
403 //******************************************************
404 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
406 ModuleBase_OperationFeature* aFOperation =
407 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
409 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
410 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
414 //******************************************************
415 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
417 ModuleBase_IModule::operationResumed(theOperation);
419 ModuleBase_OperationFeature* aFOperation =
420 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
422 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
423 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
427 //******************************************************
428 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
430 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
431 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
432 bool isModified = isModifiedArgs || isModifiedResults;
434 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
435 mySketchMgr->stopNestedSketch(theOperation);
437 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
438 setDefaultConstraintShown();
440 //VSV: Viewer is updated on feature update and redisplay
442 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
443 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
444 aDisplayer->updateViewer();
447 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
448 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
449 for (; anIt != aLast; anIt++) {
450 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
454 //******************************************************
455 ModuleBase_Operation* PartSet_Module::currentOperation() const
457 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
458 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
459 return anOpMgr->currentOperation();
462 //******************************************************
463 bool PartSet_Module::canUndo() const
465 bool aCanUndo = false;
466 SessionPtr aMgr = ModelAPI_Session::get();
467 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
468 aCanUndo = !aMgr->isOperation();
469 if (!aCanUndo) // check the enable state additionally by sketch manager
470 aCanUndo = aMgr->canUndo();
475 //******************************************************
476 bool PartSet_Module::canRedo() const
478 bool aCanRedo = false;
479 SessionPtr aMgr = ModelAPI_Session::get();
480 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
481 aCanRedo = !aMgr->isOperation();
482 if (!aCanRedo) // check the enable state additionally by sketch manager
483 aCanRedo = aMgr->canRedo();
488 //******************************************************
489 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
492 if (theActionId == "MOVE_CMD") {
493 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
495 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
496 // part features can not be moved in the history.
497 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
504 //******************************************************
505 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
507 // the sketch manager put the restriction to the objects erase
508 return mySketchMgr->canEraseObject(theObject);
511 //******************************************************
512 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
514 // the sketch manager put the restriction to the objects display
515 return mySketchMgr->canDisplayObject(theObject);
518 //******************************************************
519 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
520 const QString& theStartedOperationKind)
522 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
525 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
528 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
530 mySketchMgr->processHiddenObject(theObjects);
533 //******************************************************
534 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
536 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
538 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
539 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
540 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
541 if (isSketchOp || isNestedOp) {
542 // in active sketch operation it is possible to activate operation object in selection
543 // in the edit operation, e.g. points of the line can be moved when the line is edited
544 ModuleBase_OperationFeature* aFOperation =
545 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
546 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
551 //******************************************************
552 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
554 QMap<int, QAction*>& theMenuActions) const
556 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
559 //******************************************************
560 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
562 myMenuMgr->updateViewerMenu(theStdActions);
565 //******************************************************
566 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
568 bool isEnabledFixed = false;
569 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
570 mySketchReentrantMgr->isInternalEditActive())
571 isEnabledFixed = true;
572 return isEnabledFixed;
575 //******************************************************
576 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
578 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
579 if (anError.isEmpty())
580 anError = sketchMgr()->getFeatureError(theFeature);
585 //******************************************************
586 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
587 QStringList& theIds) const
589 myMenuMgr->grantedOperationIds(theOperation, theIds);
591 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
592 XGUI_Workshop* aWorkshop = getWorkshop();
593 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
597 //******************************************************
598 void PartSet_Module::activeSelectionModes(QIntList& theModes)
600 if (mySketchMgr->activeSketch().get())
601 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
603 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
606 //******************************************************
607 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
609 customSubShapesSelectionModes(theModes);
611 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
612 //myWorkshop->module()->activeSelectionModes(theModes);
615 //******************************************************
616 void PartSet_Module::moduleSelectionFilters(int theModesType,
617 SelectMgr_ListOfFilter& theSelectionFilters)
619 //XGUI_Tools::workshop(myWorkshop)->selectionFilters(theSelectionFilters);
620 //selectionFilters(theSelectionFilters);
622 for (SelectMgr_ListOfFilter::Iterator aFiltersIt(mySelectionFilters); aFiltersIt.More();
624 theSelectionFilters.Append(aFiltersIt.Value());
626 if (mySketchMgr->activeSketch())
627 mySketchMgr->selectionFilters(theSelectionFilters);
630 //******************************************************
631 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
633 if (theModes.contains(TopAbs_FACE))
634 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
635 if (theModes.contains(TopAbs_WIRE))
636 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
638 if (mySketchMgr->activeSketch().get())
639 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
642 //******************************************************
643 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
644 ObjectPtr& theObject, AttributePtr& theAttribute)
646 ObjectPtr anObject = theSelected->object();
647 GeomShapePtr aShape = theSelected->shape();
649 theAttribute = findAttribute(anObject, aShape);
650 // TODO: try to create result if object is an external object
651 theObject = anObject;
654 //******************************************************
655 bool PartSet_Module::isMouseOverWindow()
657 return mySketchMgr->isMouseOverWindow();
660 //******************************************************
661 bool PartSet_Module::isSketchNeutralPointActivated() const
663 bool isNeutralPoint = true;
664 if (sketchReentranceMgr()->isInternalEditActive())
665 isNeutralPoint = false;
666 if (myIsOperationIsLaunched)
667 isNeutralPoint = false;
669 return isNeutralPoint;
672 //******************************************************
673 void PartSet_Module::closeDocument()
675 myActivePartIndex = QModelIndex();
678 //******************************************************
679 void PartSet_Module::clearViewer()
681 myCustomPrs->clearPrs();
683 XGUI_Workshop* aWorkshop = getWorkshop();
684 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
685 aDisplayer->deactivateSelectionFilters(false);
688 //******************************************************
689 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
691 ModuleBase_OperationFeature* aFOperation =
692 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
696 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
697 // we have to manually activate the sketch label in edit mode
698 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
699 aPanel->activateWidget(aPanel->modelWidgets().first());
702 //******************************************************
703 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
704 QList<ModuleBase_ModelWidget*>& theWidgets) const
706 bool aProcessed = false;
708 ModuleBase_OperationFeature* aFOperation =
709 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
710 XGUI_Workshop* aWorkshop = getWorkshop();
711 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
712 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
713 ModuleBase_ISelection* aSelection = workshop()->selection();
714 // click on a point in sketch leads here with the point is highlighted, not yet selected
715 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
716 if (aPreselection.size() == 1) {
717 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
718 ObjectPtr anObject = aSelectedPrs->object();
720 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
721 FeaturePtr anOpFeature = aFOperation->feature();
722 GeomShapePtr aShape = aSelectedPrs->shape();
723 // click on the digit of dimension constrain comes here
724 // with an empty shape, so we need the check
725 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
726 // if feature has only one result and shape of result is equal to selected shape
727 // this attribute is not processed. It is a case of Sketch Point.
728 if (aFeature->results().size() == 1) {
729 ResultPtr aResult = aFeature->results().front();
730 if (aResult.get() && aResult->shape()->isEqual(aShape))
733 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
734 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
735 mySketchMgr->activeSketch());
736 if (anAttribute.get()) {
737 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
738 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
740 const std::string anAttributeId = anAttribute->id();
741 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
743 theWidgets = aFactory.getModelWidgets();
744 // it is possible that the point does not present in XML definition,
745 // in this case, we assume that it is not processed by this module
746 // e.g. "Intersection point" feature
747 aProcessed = !theWidgets.isEmpty();
755 //******************************************************
756 void PartSet_Module::onSelectionChanged()
758 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
762 bool isSketcherOp = false;
763 // An edit operation is enable only if the current opeation is the sketch operation
764 if (mySketchMgr->activeSketch()) {
765 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
766 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
769 // Editing of constraints can be done on selection
770 ModuleBase_ISelection* aSelect = myWorkshop->selection();
771 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
772 if (aSelected.size() == 1) {
773 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
774 ObjectPtr aObject = aPrs->object();
775 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
777 std::string aId = aFeature->getKind();
778 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
779 (aId == SketchPlugin_ConstraintLength::ID()) ||
780 (aId == SketchPlugin_ConstraintDistance::ID()) ||
781 (aId == SketchPlugin_ConstraintAngle::ID())) {
782 editFeature(aFeature);
789 //******************************************************
790 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
792 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
793 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
794 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
797 //******************************************************
798 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
800 Config_WidgetAPI* theWidgetApi)
802 ModuleBase_IWorkshop* aWorkshop = workshop();
803 XGUI_Workshop* aXUIWorkshop = getWorkshop();
804 ModuleBase_ModelWidget* aWgt = NULL;
805 if (theType == "sketch-start-label") {
806 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
807 theWidgetApi, myHasConstraintShown);
808 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
809 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
810 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
811 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
813 } else if (theType == "sketch-2dpoint_selector") {
814 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
816 aPointWgt->setSketch(mySketchMgr->activeSketch());
817 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
819 }else if (theType == "sketch-2dpoint_flyout_selector") {
820 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
822 aPointWgt->setSketch(mySketchMgr->activeSketch());
823 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
825 } else if (theType == "sketch_shape_selector") {
826 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
827 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
828 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
829 aWgt = aShapeSelectorWgt;
830 } else if (theType == "sketch_multi_selector") {
831 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
832 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
833 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
834 aWgt = aShapeSelectorWgt;
836 else if (theType == "sketch_feature_point_selector") {
837 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
838 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
839 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
840 aWgt = aPointSelectorWgt;
842 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
843 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
844 } else if (theType == "export_file_selector") {
845 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
846 } else if (theType == "sketch_launcher") {
847 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
848 } else if (theType == "module_choice") {
849 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
850 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
851 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
856 //******************************************************
857 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
859 ModuleBase_ModelWidget* anActiveWidget = 0;
861 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
862 if (!anActiveWidget) {
863 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
865 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
866 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
869 return anActiveWidget;
872 //******************************************************
873 bool PartSet_Module::deleteObjects()
875 bool isProcessed = false;
877 XGUI_Workshop* aWorkshop = getWorkshop();
878 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
880 //SessionPtr aMgr = ModelAPI_Session::get();
881 // 1. check whether the delete should be processed in the module
882 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
883 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
884 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
885 if (isSketchOp || isNestedOp) {
887 // 2. find selected presentations
888 // selected objects should be collected before the current operation abort because
889 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
890 ModuleBase_ISelection* aSel = workshop()->selection();
891 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
892 // if there are no selected objects in the viewer, that means that the selection in another
893 // place cased this method. It is necessary to return the false value to understande in above
894 // method that delete is not processed
895 if (aSelectedObj.count() == 0)
898 // avoid delete of the objects, which are not belong to the current sketch
899 // in order to do not delete results of other sketches
900 QObjectPtrList aSketchObjects;
901 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
902 for ( ; anIt != aLast; anIt++) {
903 ObjectPtr anObject = *anIt;
904 if (mySketchMgr->isObjectOfSketch(anObject)) {
905 // sketch feature should be used in this list because workshop deletes features only
906 // results are skipped
907 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
908 aSketchObjects.append(aSketchFeature);
911 // if the selection contains only local selected presentations from other sketches,
912 // the Delete operation should not be done at all
913 if (aSketchObjects.size() == 0)
916 // 3. start operation
917 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
918 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
920 // the active nested sketch operation should be aborted unconditionally
921 // the Delete action should be additionally granted for the Sketch operation
922 // in order to do not abort/commit it
924 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
925 return true; // the objects are processed but can not be deleted
927 anOpMgr->startOperation(anOpAction);
929 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
930 // the problem is in AIS Dimensions recompute
931 // if a line and the dim are removed, line is the first
932 // it causes the AIS recompute, where the base line is null,
933 // the result is empty AIS in the viewer
934 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
936 // 4. delete features
937 // sketch feature should be skipped, only sub-features can be removed
938 // when sketch operation is active
939 aWorkshop->deleteFeatures(aSketchObjects);
941 anOpMgr->commitOperation();
946 //******************************************************
947 void PartSet_Module::editFeature(FeaturePtr theFeature)
949 storeConstraintsState(theFeature->getKind());
950 ModuleBase_IModule::editFeature(theFeature);
953 //******************************************************
954 bool PartSet_Module::canCommitOperation() const
959 //******************************************************
960 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
962 myIsOperationIsLaunched = true;
963 storeConstraintsState(theCmdId.toStdString());
964 updateConstraintsState(theCmdId.toStdString());
966 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
968 myIsOperationIsLaunched = false;
971 //******************************************************
972 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
974 if (myWorkshop->currentOperation() &&
975 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
976 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
977 mySketchMgr->showConstraintStates();
978 myHasConstraintShown = aShownStates;
982 //******************************************************
983 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
985 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
986 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
987 // Show constraints if a constraint was anOperation
988 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
989 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
990 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
991 myHasConstraintShown[PartSet_Tools::Expressions]);
995 //******************************************************
996 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
998 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
999 if (!anAIS.IsNull()) {
1000 bool aToUseZLayer = false;
1001 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1002 if (aFeature.get() && PartSet_Tools::findRefsToMeFeature(aFeature,
1003 SketchPlugin_Projection::ID()))
1004 aToUseZLayer = true;
1005 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1006 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
1007 if (!aDim.IsNull()) {
1008 aToUseZLayer = true;
1010 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
1011 if (!aCons.IsNull())
1012 aToUseZLayer = true;
1015 aCtx->SetZLayer(anAIS, myVisualLayerId);
1019 //******************************************************
1020 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1023 // it should be recomputed in order to disappear in the viewer if the corresponded object
1025 //if (myCustomPrs->isActive())
1026 // myCustomPrs->redisplay(theObject, false);
1029 //******************************************************
1030 void PartSet_Module::onViewTransformed(int theTrsfType)
1032 // Set length of arrows constant in pixel size
1033 // if the operation is panning or rotate or panglobal then do nothing
1034 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1036 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1037 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1038 if (aContext.IsNull())
1041 //Handle(V3d_View) aView = aViewer->activeView();
1043 XGUI_Workshop* aWorkshop = getWorkshop();
1044 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1045 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1046 Handle(V3d_View) aView;
1048 for (aV3dViewer->InitDefinedViews();
1049 aV3dViewer->MoreDefinedViews();
1050 aV3dViewer->NextDefinedViews()) {
1051 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1052 double aS = aV->Scale();
1061 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1062 if (aCurrentOperation &&
1063 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1064 sketchMgr()->isNestedSketchOperation(aCurrentOperation)))
1066 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1068 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1069 SketcherPrs_Tools::setArrowSize(aLen);
1070 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1071 aViewer->SetScale(aViewer->activeView(), aCurScale);
1072 bool isModified = false;
1073 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1074 foreach (AISObjectPtr aAIS, aPrsList) {
1075 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1077 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1078 if (!aDim.IsNull()) {
1079 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1080 aContext->Redisplay(aDim, false);
1085 aDisplayer->updateViewer();
1089 //******************************************************
1090 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1092 return myCustomPrs->isActive(theFlag);
1095 //******************************************************
1096 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1097 const ModuleBase_CustomizeFlag& theFlag,
1098 const bool theUpdateViewer)
1100 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1103 //******************************************************
1104 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1105 const bool theUpdateViewer)
1107 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1110 //******************************************************
1111 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1112 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1114 bool aCustomized = false;
1116 XGUI_Workshop* aWorkshop = getWorkshop();
1117 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1118 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1122 if (!theResult.get()) {
1123 std::vector<int> aColor;
1124 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1125 if (!aColor.empty()) {
1126 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1129 // customize dimentional constrains
1130 sketchMgr()->customizePresentation(anObject);
1135 //******************************************************
1136 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1137 AISObjectPtr thePrs,
1138 GeomCustomPrsPtr theCustomPrs)
1140 bool aCustomized = false;
1142 XGUI_Workshop* aWorkshop = getWorkshop();
1143 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1144 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1148 std::vector<int> aColor;
1149 bool aUseCustomColor = true;
1150 if (aUseCustomColor)
1151 myOverconstraintListener->getCustomColor(anObject, aColor);
1152 // customize sketch symbol presentation
1153 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1154 if (!anAISIO.IsNull()) {
1155 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1156 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1157 if (!aPrs.IsNull()) {
1158 aPrs->SetCustomColor(aColor);
1161 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1162 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1163 if (!aPrs.IsNull()) {
1164 aPrs->SetCustomColor(aColor);
1169 // customize sketch dimension constraint presentation
1171 if (!aColor.empty()) { // otherwise presentation has the default color
1172 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1178 //******************************************************
1179 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1180 const bool theUpdateViewer)
1182 bool isRedisplayed = false;
1183 if (myCustomPrs->isActive(theFlag))
1184 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1186 return isRedisplayed;
1189 //******************************************************
1190 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1192 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1194 QLabel* aLabel = aOB->activeDocLabel();
1195 aLabel->installEventFilter(myMenuMgr);
1196 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1197 SLOT(onActiveDocPopup(const QPoint&)));
1198 aOB->treeView()->setExpandsOnDoubleClick(false);
1199 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1200 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1202 Events_Loop* aLoop = Events_Loop::loop();
1203 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1207 //******************************************************
1208 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1210 SessionPtr aMgr = ModelAPI_Session::get();
1211 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1213 XGUI_Workshop* aWorkshop = getWorkshop();
1214 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1216 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1219 aMenu.addAction(aActivatePartAction);
1220 aMenu.exec(aHeader->mapToGlobal(thePnt));
1223 //******************************************************
1224 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1226 return mySketchMgr->createPresentation(theResult);
1229 //******************************************************
1230 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1233 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1235 /// If last line finished on vertex the lines creation sequence has to be break
1236 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1238 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1239 // if there is an active widget, find the presented object in it
1240 if (!anActiveWidget)
1241 anActiveWidget = aPanel->preselectionWidget();
1243 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1245 if (aWidgetValidated)
1246 anObject = aWidgetValidated->findPresentedObject(theAIS);
1252 //******************************************************
1253 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1255 bool aCanBeShaged = true;
1257 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1259 aCanBeShaged = false;
1261 return aCanBeShaged;
1264 //******************************************************
1265 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1267 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1268 int aSelected = aObjects.size();
1269 SessionPtr aMgr = ModelAPI_Session::get();
1270 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1272 bool hasResult = false;
1273 bool hasFeature = false;
1274 bool hasParameter = false;
1275 bool hasCompositeOwner = false;
1276 bool hasResultInHistory = false;
1277 bool hasFolder = false;
1278 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1279 hasCompositeOwner, hasResultInHistory, hasFolder);
1281 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1282 if (aSelected == 1) {
1283 ObjectPtr aObject = aObjects.first();
1285 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1286 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1287 bool isPart = aPart.get() ||
1288 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1290 DocumentPtr aPartDoc;
1292 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1294 if (aPart.get()) // this may be null is Part feature is disabled
1295 aPartDoc = aPart->partDoc();
1297 theMenu->addAction(aActivatePartAction);
1298 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1300 } else if (aObject->document() == aMgr->activeDocument()) {
1301 if (hasParameter || hasFeature) {
1302 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1303 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1304 if (aCurrentOp && aFeature.get()) {
1305 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1306 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1313 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1314 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1315 theMenu->addSeparator();
1318 bool aNotDeactivate = (aCurrentOp == 0);
1319 if (!aNotDeactivate) {
1320 aActivatePartAction->setEnabled(false);
1324 //******************************************************
1325 #define EXPAND_PARENT(OBJ) \
1326 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1327 if (aObjIndex.isValid()) { \
1328 QModelIndex aParent = aObjIndex.parent(); \
1329 int aCount = aDataModel->rowCount(aParent); \
1331 aTreeView->setExpanded(aParent, true); \
1334 //******************************************************
1335 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1337 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1338 // Do not change activation of parts if an operation active
1339 static QStringList aAllowActivationList;
1340 if (aAllowActivationList.isEmpty())
1341 aAllowActivationList <<
1342 QString(PartSetPlugin_Part::ID().c_str()) <<
1343 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1344 QString(PartSetPlugin_Remove::ID().c_str());
1345 if (myWorkshop->currentOperation() &&
1346 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1348 XGUI_Workshop* aWorkshop = getWorkshop();
1349 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1350 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1351 QPalette aPalet = aLabel->palette();
1353 SessionPtr aMgr = ModelAPI_Session::get();
1354 DocumentPtr aActiveDoc = aMgr->activeDocument();
1355 if (myActivePartIndex.isValid())
1356 aTreeView->setExpanded(myActivePartIndex, false);
1358 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1359 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1360 bool needUpdate = false;
1361 if (myActivePartIndex.isValid()) {
1362 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1364 aTreeView->setExpanded(myActivePartIndex, true);
1367 aLabel->setPalette(aPalet);
1368 aWorkshop->updateCommandStatus();
1370 // Update displayed objects in order to update active color
1371 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1372 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1374 foreach(ObjectPtr aObj, aObjects) {
1375 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1376 aObj->isDisabled() || (!aObj->isDisplayed());
1378 aDisplayer->redisplay(aObj, false);
1380 aDisplayer->updateViewer();
1381 // Update tree items if they are expanded
1383 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1385 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1386 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1387 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1388 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1390 ObjectPtr aConstrObj;
1391 ObjectPtr aResultObj;
1392 std::set<ObjectPtr>::const_iterator aIt;
1393 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1394 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1395 ObjectPtr aObject = (*aIt);
1396 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1397 && (aObject->document() != aRootDoc))
1398 aResultObj = aObject;
1399 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1400 && (aObject->document() != aRootDoc))
1401 aConstrObj = aObject;
1402 if (aResultObj.get() && aConstrObj.get())
1406 if (aResultObj.get() || aConstrObj.get()) {
1407 XGUI_Workshop* aWorkshop = getWorkshop();
1408 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1409 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1411 if (aResultObj.get()) {
1412 EXPAND_PARENT(aResultObj)
1414 if (aConstrObj.get()) {
1415 EXPAND_PARENT(aConstrObj)
1421 //******************************************************
1422 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1424 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1426 SessionPtr aMgr = ModelAPI_Session::get();
1427 if (!theIndex.isValid()) {
1428 // It seems that this code is obsolete
1429 //aMgr->setActiveDocument(aMgr->moduleDocument());
1432 if (theIndex.column() != 1) // Use only first column
1435 XGUI_Workshop* aWorkshop = getWorkshop();
1436 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1437 // De not use non editable Indexes
1438 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1440 ObjectPtr aObj = aDataModel->object(theIndex);
1442 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1443 if (!aPart.get()) { // Probably this is Feature
1444 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1445 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1446 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1449 if (aPart.get()) { // if this is a part
1450 if (aPart->partDoc() == aMgr->activeDocument()) {
1451 myMenuMgr->activatePartSet();
1453 myMenuMgr->activatePart(aPart);
1458 //******************************************************
1459 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1461 // z layer is created for all started operations in order to visualize operation AIS presentation
1463 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1464 if (aContext.IsNull())
1467 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1468 if (myVisualLayerId == 0) {
1469 if (myVisualLayerId == 0)
1470 aViewer->AddZLayer(myVisualLayerId);
1472 TColStd_SequenceOfInteger aZList;
1473 aViewer->GetAllZLayers(aZList);
1474 bool aFound = false;
1475 for (int i = 1; i <= aZList.Length(); i++) {
1476 if (aZList(i) == myVisualLayerId) {
1482 aViewer->AddZLayer(myVisualLayerId);
1484 // if there is an active operation with validated widget,
1485 // the filters of this widget should be activated in the created view
1486 myWorkshop->selectionActivate()->updateSelectionFilters();
1487 myWorkshop->selectionActivate()->updateSelectionModes();
1490 //******************************************************
1491 void PartSet_Module::widgetStateChanged(int thePreviousState)
1493 mySketchMgr->widgetStateChanged(thePreviousState);
1496 //******************************************************
1497 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1499 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1502 //******************************************************
1503 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1505 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1506 mySketchMgr->stopSketch(theOperation);
1510 //******************************************************
1511 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1513 GeomShapePtr aGeomShape;
1515 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1516 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1517 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1522 //******************************************************
1523 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1524 const GeomShapePtr& theGeomShape)
1526 AttributePtr anAttribute;
1527 GeomShapePtr aGeomShape = theGeomShape;
1528 if (!aGeomShape.get()) {
1529 // processing shape of result, e.g. sketch circle center is selected, this is a result
1530 // the geom shape is empty, the shape of result should be used
1531 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1532 if (aResult.get()) {
1533 aGeomShape = aResult->shape();
1537 if (aGeomShape.get()) {
1538 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1539 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1540 mySketchMgr->activeSketch());
1545 //******************************************************
1546 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1548 return sketchReentranceMgr()->reentrantMessage();
1551 //******************************************************
1552 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1554 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1557 //******************************************************
1558 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1561 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1565 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1566 if (!aChoiceTitle.isEmpty()) {
1567 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1570 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1572 aPanel->setWindowTitle(aChoiceTitle);
1576 //******************************************************
1577 XGUI_Workshop* PartSet_Module::getWorkshop() const
1579 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1580 return aConnector->workshop();
1583 //******************************************************
1584 void PartSet_Module::setDefaultConstraintShown()
1586 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1587 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1588 myHasConstraintShown[PartSet_Tools::Expressions] = false;