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_WidgetChoice.h>
55 #include <ModuleBase_WidgetEditor.h>
56 #include <ModuleBase_WidgetValidated.h>
57 #include <ModuleBase_Tools.h>
58 #include <ModuleBase_OperationFeature.h>
59 #include <ModuleBase_WidgetFactory.h>
60 #include <ModuleBase_OperationDescription.h>
61 #include <ModuleBase_ViewerPrs.h>
63 #include <ModelAPI_Object.h>
64 #include <ModelAPI_Events.h>
65 #include <ModelAPI_Validator.h>
66 #include <ModelAPI_Data.h>
67 #include <ModelAPI_Session.h>
68 #include <ModelAPI_ResultBody.h>
69 #include <ModelAPI_AttributeString.h>
70 #include <ModelAPI_AttributeSelectionList.h>
71 #include <ModelAPI_Tools.h>
72 #include <ModelAPI_ResultConstruction.h>
74 #include <GeomDataAPI_Point2D.h>
75 #include <GeomDataAPI_Point.h>
76 #include <GeomDataAPI_Dir.h>
78 #include <XGUI_Displayer.h>
79 #include <XGUI_Workshop.h>
80 #include <XGUI_OperationMgr.h>
81 #include <XGUI_PropertyPanel.h>
82 #include <XGUI_ModuleConnector.h>
83 #include <XGUI_ContextMenuMgr.h>
84 #include <XGUI_Tools.h>
85 #include <XGUI_ObjectsBrowser.h>
86 #include <XGUI_SelectionMgr.h>
87 #include <XGUI_DataModel.h>
88 #include <XGUI_ErrorMgr.h>
89 #include <XGUI_CustomPrs.h>
90 #include <XGUI_SelectionMgr.h>
91 #include <XGUI_ActionsMgr.h>
93 #include <SketchPlugin_ConstraintAngle.h>
94 #include <SketchPlugin_ConstraintLength.h>
95 #include <SketchPlugin_ConstraintDistance.h>
96 #include <SketchPlugin_ConstraintParallel.h>
97 #include <SketchPlugin_ConstraintPerpendicular.h>
98 #include <SketchPlugin_ConstraintRadius.h>
99 #include <SketchPlugin_Feature.h>
100 #include <SketchPlugin_Projection.h>
101 #include <SketchPlugin_Sketch.h>
103 #include <SketcherPrs_SymbolPrs.h>
104 #include <SketcherPrs_Coincident.h>
105 #include <SketcherPrs_Tools.h>
107 #include <Events_Loop.h>
108 #include <Config_PropManager.h>
109 #include <Config_Keywords.h>
111 #include <AIS_Dimension.hxx>
112 #include <AIS_InteractiveObject.hxx>
113 #include <StdSelect_TypeOfFace.hxx>
114 #include <TopoDS_Vertex.hxx>
115 #include <TopoDS.hxx>
116 #include <TopoDS_Shape.hxx>
117 #include <BRep_Tool.hxx>
120 #include <QMouseEvent>
123 #include <QApplication>
124 #include <QMessageBox>
125 #include <QMainWindow>
129 #include <GeomAlgoAPI_FaceBuilder.h>
130 #include <GeomDataAPI_Dir.h>
132 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
138 /*!Create and return new instance of XGUI_Module*/
139 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
141 return new PartSet_Module(theWshop);
144 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
145 : ModuleBase_IModule(theWshop),
147 myIsOperationIsLaunched(false)
149 new PartSet_IconFactory();
151 mySketchMgr = new PartSet_SketcherMgr(this);
152 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
154 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
155 XGUI_Workshop* aWorkshop = aConnector->workshop();
157 ModuleBase_IViewer* aViewer = theWshop->viewer();
158 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
159 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
160 connect(aViewer, SIGNAL(viewTransformed(int)),
161 SLOT(onViewTransformed(int)));
162 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
163 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
164 myMenuMgr = new PartSet_MenuMgr(this);
165 myCustomPrs = new PartSet_CustomPrs(theWshop);
167 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
169 Events_Loop* aLoop = Events_Loop::loop();
170 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
172 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
173 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
175 setDefaultConstraintShown();
177 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
178 "Reference shape wireframe color in operation", Config_Prop::Color,
179 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
180 Config_PropManager::registerProp("Visualization", "operation_result_color",
181 "Result shape wireframe color in operation", Config_Prop::Color,
182 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
183 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
184 "Multi selector item color in operation", Config_Prop::Color,
185 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
186 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
187 "Color of removed feature in operation", Config_Prop::Color,
188 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
189 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
190 "Color of sketch plane", Config_Prop::Color,
191 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
194 PartSet_Module::~PartSet_Module()
196 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
197 for (; aIt.More(); aIt.Next()) {
198 Handle(SelectMgr_Filter) aFilter = aIt.Value();
199 if (!aFilter.IsNull())
203 delete myOverconstraintListener;
206 void PartSet_Module::activateSelectionFilters()
208 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
209 for (; aIt.More(); aIt.Next()) {
210 Handle(SelectMgr_Filter) aFilter = aIt.Value();
211 if (!aFilter.IsNull())
212 myWorkshop->viewer()->addSelectionFilter(aFilter);
216 void PartSet_Module::deactivateSelectionFilters()
218 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
219 for (; aIt.More(); aIt.Next()) {
220 Handle(SelectMgr_Filter) aFilter = aIt.Value();
221 if (!aFilter.IsNull())
222 myWorkshop->viewer()->removeSelectionFilter(aFilter);
226 void PartSet_Module::storeSelection()
228 // cash is used only to restore selection, so it should be filled in storeSelection and
229 // after applying immediatelly cleared in restoreSelection
230 myCurrentSelection.clear();
231 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
234 void PartSet_Module::restoreSelection()
236 // cash is used only to restore selection, so it should be filled in storeSelection and
237 // after applying immediatelly cleared in restoreSelection
238 sketchMgr()->restoreSelection(myCurrentSelection);
239 myCurrentSelection.clear();
242 void PartSet_Module::registerValidators()
244 //Registering of validators
245 SessionPtr aMgr = ModelAPI_Session::get();
246 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
247 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
248 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
249 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
250 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
251 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
252 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
253 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
254 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
255 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
256 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
257 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
258 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
259 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
260 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
261 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
262 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
263 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
264 aFactory->registerValidator("PartSet_MultyTranslationSelection",
265 new PartSet_MultyTranslationSelection);
266 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
267 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
270 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
271 const bool isToConnect)
273 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
276 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
278 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
279 mySketchMgr->commitNestedSketch(theOperation);
281 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
282 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
283 overconstraintListener()->setActive(false);
285 /// Restart sketcher operations automatically
286 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
288 ModuleBase_OperationFeature* aFOperation =
289 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
290 if (aFOperation && !aFOperation->isEditOperation()) {
291 // the selection is cleared after commit the create operation
292 // in order to do not use the same selected objects in the restarted operation
293 // for common behaviour, the selection is cleared even if the operation is not restarted
294 getWorkshop()->selector()->clearSelection();
299 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
301 /// Restart sketcher operations automatically
302 mySketchReentrantMgr->operationAborted(theOperation);
303 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
304 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
305 overconstraintListener()->setActive(false);
308 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
310 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
313 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
314 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
316 ModuleBase_ModelWidget* aFilledWidget = 0;
317 bool aPostonedWidgetActivation = false;
319 FeaturePtr aFeature = aFOperation->feature();
320 /// Restart sketcher operations automatically
321 /// it is important to call method of sketch reentrant manager before filling of PP
322 /// because it fills some created feature attributes, these new values should be used
323 /// to fill the property panel
324 mySketchReentrantMgr->operationStarted(theOperation);
326 aWorkshop->fillPropertyPanel(aFOperation);
327 // filling the operation values by the current selection
328 // if the operation can be committed after the controls filling, the method perform should
329 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
330 bool isOperationCommitted = false;
331 if (!aFOperation->isEditOperation()) {
332 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
333 // if there is a greed attribute, automatic commit by preselection
334 // for this feature is prohibited
335 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
336 if (currentOperation() != aFOperation)
337 isOperationCommitted = true;
339 if (aGreedAttributeId.empty()) {
340 // a signal should be emitted before the next widget activation
341 // because, the activation of the next widget will give a focus to the widget.
342 // As a result the value of the widget is initialized.
343 // And commit may happens until the value is entered.
345 if (mySketchReentrantMgr->canBeCommittedByPreselection())
346 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
347 // activate the next obligatory widget
348 if (!isOperationCommitted)
349 aPropertyPanel->activateNextWidget(aFilledWidget);
352 else { // there is a greed widget
353 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
354 std::string aFirstAttributeId = aWidgets.front()->attributeID();
355 // activate next widget after greeded if it is the first widget in the panel
356 // else the first panel widget is already activated by operation start
357 if (aFirstAttributeId == aGreedAttributeId)
358 aPostonedWidgetActivation = true;
361 } if (!isOperationCommitted) {
362 aWorkshop->connectToPropertyPanel(true);
363 updateSketcherOnStart(aFOperation);
364 updatePresentationsOnStart(aFOperation);
366 // the objects of the current operation should be deactivated
367 QObjectPtrList anObjects;
368 anObjects.append(aFeature);
369 std::list<ResultPtr> aResults;
370 ModelAPI_Tools::allResults(aFeature, aResults);
371 std::list<ResultPtr>::const_iterator aIt;
372 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
373 anObjects.append(*aIt);
375 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
376 for (; anIt != aLast; anIt++)
377 aWorkshop->deactivateActiveObject(*anIt, false);
378 if (anObjects.size() > 0) {
379 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
380 aDisplayer->updateViewer();
382 /// state of command actions should be updated after displayed objects modification because
383 /// deactivation(for example) of objects may influence on selection in the viewer
384 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
385 workshop()->updateCommandStatus();
387 if (aPostonedWidgetActivation) {
388 // if the widget is an empty in the chain of activated widgets, the current operation
389 // is restarted. It should be performed after functionality of the operation starting
390 aPropertyPanel->activateNextWidget(aFilledWidget);
395 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
397 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
398 mySketchMgr->startSketch(theOperation);
400 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
401 mySketchMgr->startNestedSketch(theOperation);
405 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
407 ModuleBase_OperationFeature* aFOperation =
408 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
410 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
411 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
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 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
429 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
430 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
431 bool isModified = isModifiedArgs || isModifiedResults;
433 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
434 mySketchMgr->stopNestedSketch(theOperation);
436 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
437 setDefaultConstraintShown();
439 //VSV: Viewer is updated on feature update and redisplay
441 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
442 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
443 aDisplayer->updateViewer();
446 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
447 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
448 for (; anIt != aLast; anIt++) {
449 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
453 ModuleBase_Operation* PartSet_Module::currentOperation() const
455 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
456 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
457 return anOpMgr->currentOperation();
460 bool PartSet_Module::canUndo() const
462 bool aCanUndo = false;
463 SessionPtr aMgr = ModelAPI_Session::get();
464 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
465 aCanUndo = !aMgr->isOperation();
466 if (!aCanUndo) // check the enable state additionally by sketch manager
467 aCanUndo = aMgr->canUndo();
472 bool PartSet_Module::canRedo() const
474 bool aCanRedo = false;
475 SessionPtr aMgr = ModelAPI_Session::get();
476 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
477 aCanRedo = !aMgr->isOperation();
478 if (!aCanRedo) // check the enable state additionally by sketch manager
479 aCanRedo = aMgr->canRedo();
484 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
487 if (theActionId == "MOVE_CMD") {
488 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
490 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
491 // part features can not be moved in the history.
492 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
499 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
501 // the sketch manager put the restriction to the objects erase
502 return mySketchMgr->canEraseObject(theObject);
505 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
507 // the sketch manager put the restriction to the objects display
508 return mySketchMgr->canDisplayObject(theObject);
511 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
512 const QString& theStartedOperationKind)
514 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
517 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
520 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
522 mySketchMgr->processHiddenObject(theObjects);
525 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
527 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
529 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
530 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
531 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
532 if (isSketchOp || isNestedOp) {
533 // in active sketch operation it is possible to activate operation object in selection
534 // in the edit operation, e.g. points of the line can be moved when the line is edited
535 ModuleBase_OperationFeature* aFOperation =
536 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
537 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
542 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
544 QMap<int, QAction*>& theMenuActions) const
546 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
549 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
551 myMenuMgr->updateViewerMenu(theStdActions);
554 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
556 bool isEnabledFixed = false;
557 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
558 mySketchReentrantMgr->isInternalEditActive())
559 isEnabledFixed = true;
560 return isEnabledFixed;
563 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
565 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
566 if (anError.isEmpty())
567 anError = sketchMgr()->getFeatureError(theFeature);
572 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
573 QStringList& theIds) const
575 myMenuMgr->grantedOperationIds(theOperation, theIds);
577 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
578 XGUI_Workshop* aWorkshop = getWorkshop();
579 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
583 void PartSet_Module::activeSelectionModes(QIntList& theModes)
586 if (mySketchMgr->activeSketch().get())
587 PartSet_SketcherMgr::sketchSelectionModes(theModes);
590 void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
592 if (theTypes.contains(TopAbs_FACE))
593 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
594 if (theTypes.contains(TopAbs_WIRE))
595 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
598 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
599 ObjectPtr& theObject, AttributePtr& theAttribute)
601 ObjectPtr anObject = theSelected->object();
602 GeomShapePtr aShape = theSelected->shape();
604 theAttribute = findAttribute(anObject, aShape);
605 // TODO: try to create result if object is an external object
606 theObject = anObject;
609 bool PartSet_Module::isMouseOverWindow()
611 return mySketchMgr->isMouseOverWindow();
614 bool PartSet_Module::isSketchNeutralPointActivated() const
616 bool isNeutralPoint = true;
617 if (sketchReentranceMgr()->isInternalEditActive())
618 isNeutralPoint = false;
619 if (myIsOperationIsLaunched)
620 isNeutralPoint = false;
622 return isNeutralPoint;
625 void PartSet_Module::closeDocument()
627 myActivePartIndex = QModelIndex();
630 void PartSet_Module::clearViewer()
632 myCustomPrs->clearPrs();
634 XGUI_Workshop* aWorkshop = getWorkshop();
635 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
636 aDisplayer->deactivateSelectionFilters();
639 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
641 ModuleBase_OperationFeature* aFOperation =
642 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
646 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
647 // we have to manually activate the sketch label in edit mode
648 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
649 aPanel->activateWidget(aPanel->modelWidgets().first());
652 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
653 QList<ModuleBase_ModelWidget*>& theWidgets) const
655 bool aProcessed = false;
657 ModuleBase_OperationFeature* aFOperation =
658 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
659 XGUI_Workshop* aWorkshop = getWorkshop();
660 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
661 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
662 ModuleBase_ISelection* aSelection = workshop()->selection();
663 // click on a point in sketch leads here with the point is highlighted, not yet selected
664 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
665 if (aPreselection.size() == 1) {
666 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
667 ObjectPtr anObject = aSelectedPrs->object();
669 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
670 FeaturePtr anOpFeature = aFOperation->feature();
671 GeomShapePtr aShape = aSelectedPrs->shape();
672 // click on the digit of dimension constrain comes here
673 // with an empty shape, so we need the check
674 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
675 // if feature has only one result and shape of result is equal to selected shape
676 // this attribute is not processed. It is a case of Sketch Point.
677 if (aFeature->results().size() == 1) {
678 ResultPtr aResult = aFeature->results().front();
679 if (aResult.get() && aResult->shape()->isEqual(aShape))
682 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
683 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
684 mySketchMgr->activeSketch());
685 if (anAttribute.get()) {
686 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
687 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
689 const std::string anAttributeId = anAttribute->id();
690 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
692 theWidgets = aFactory.getModelWidgets();
693 // it is possible that the point does not present in XML definition,
694 // in this case, we assume that it is not processed by this module
695 // e.g. "Intersection point" feature
696 aProcessed = !theWidgets.isEmpty();
704 void PartSet_Module::onSelectionChanged()
706 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
710 bool isSketcherOp = false;
711 // An edit operation is enable only if the current opeation is the sketch operation
712 if (mySketchMgr->activeSketch()) {
713 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
714 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
717 // Editing of constraints can be done on selection
718 ModuleBase_ISelection* aSelect = myWorkshop->selection();
719 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
720 if (aSelected.size() == 1) {
721 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
722 ObjectPtr aObject = aPrs->object();
723 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
725 std::string aId = aFeature->getKind();
726 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
727 (aId == SketchPlugin_ConstraintLength::ID()) ||
728 (aId == SketchPlugin_ConstraintDistance::ID()) ||
729 (aId == SketchPlugin_ConstraintAngle::ID())) {
730 editFeature(aFeature);
737 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
739 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
740 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
741 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
744 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
746 Config_WidgetAPI* theWidgetApi)
748 ModuleBase_IWorkshop* aWorkshop = workshop();
749 XGUI_Workshop* aXUIWorkshop = getWorkshop();
750 ModuleBase_ModelWidget* aWgt = NULL;
751 if (theType == "sketch-start-label") {
752 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
753 theWidgetApi, myHasConstraintShown);
754 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
755 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
756 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
757 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
759 } else if (theType == "sketch-2dpoint_selector") {
760 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
762 aPointWgt->setSketch(mySketchMgr->activeSketch());
763 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
765 }else if (theType == "sketch-2dpoint_flyout_selector") {
766 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
768 aPointWgt->setSketch(mySketchMgr->activeSketch());
769 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
771 } else if (theType == "sketch_shape_selector") {
772 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
773 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
774 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
775 aWgt = aShapeSelectorWgt;
776 } else if (theType == "sketch_multi_selector") {
777 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
778 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
779 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
780 aWgt = aShapeSelectorWgt;
782 else if (theType == "sketch_feature_point_selector") {
783 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
784 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
785 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
786 aWgt = aPointSelectorWgt;
788 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
789 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
790 } else if (theType == "export_file_selector") {
791 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
792 } else if (theType == "sketch_launcher") {
793 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
794 } else if (theType == "module_choice") {
795 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
796 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
797 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
802 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
804 ModuleBase_ModelWidget* anActiveWidget = 0;
806 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
807 if (!anActiveWidget) {
808 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
810 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
811 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
814 return anActiveWidget;
817 bool PartSet_Module::deleteObjects()
819 bool isProcessed = false;
821 XGUI_Workshop* aWorkshop = getWorkshop();
822 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
824 //SessionPtr aMgr = ModelAPI_Session::get();
825 // 1. check whether the delete should be processed in the module
826 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
827 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
828 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
829 if (isSketchOp || isNestedOp) {
831 // 2. find selected presentations
832 // selected objects should be collected before the current operation abort because
833 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
834 ModuleBase_ISelection* aSel = workshop()->selection();
835 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
836 // if there are no selected objects in the viewer, that means that the selection in another
837 // place cased this method. It is necessary to return the false value to understande in above
838 // method that delete is not processed
839 if (aSelectedObj.count() == 0)
842 // avoid delete of the objects, which are not belong to the current sketch
843 // in order to do not delete results of other sketches
844 QObjectPtrList aSketchObjects;
845 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
846 for ( ; anIt != aLast; anIt++) {
847 ObjectPtr anObject = *anIt;
848 if (mySketchMgr->isObjectOfSketch(anObject)) {
849 // sketch feature should be used in this list because workshop deletes features only
850 // results are skipped
851 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
852 aSketchObjects.append(aSketchFeature);
855 // if the selection contains only local selected presentations from other sketches,
856 // the Delete operation should not be done at all
857 if (aSketchObjects.size() == 0)
860 // 3. start operation
861 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
862 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
864 // the active nested sketch operation should be aborted unconditionally
865 // the Delete action should be additionally granted for the Sketch operation
866 // in order to do not abort/commit it
868 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
869 return true; // the objects are processed but can not be deleted
871 anOpMgr->startOperation(anOpAction);
873 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
874 // the problem is in AIS Dimensions recompute
875 // if a line and the dim are removed, line is the first
876 // it causes the AIS recompute, where the base line is null,
877 // the result is empty AIS in the viewer
878 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
880 // 4. delete features
881 // sketch feature should be skipped, only sub-features can be removed
882 // when sketch operation is active
883 aWorkshop->deleteFeatures(aSketchObjects);
885 anOpMgr->commitOperation();
890 void PartSet_Module::editFeature(FeaturePtr theFeature)
892 storeConstraintsState(theFeature->getKind());
893 ModuleBase_IModule::editFeature(theFeature);
896 bool PartSet_Module::canCommitOperation() const
901 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
903 myIsOperationIsLaunched = true;
904 storeConstraintsState(theCmdId.toStdString());
905 updateConstraintsState(theCmdId.toStdString());
907 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
909 myIsOperationIsLaunched = false;
912 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
914 if (myWorkshop->currentOperation() &&
915 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
916 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
917 mySketchMgr->showConstraintStates();
918 myHasConstraintShown = aShownStates;
922 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
924 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
925 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
926 // Show constraints if a constraint was anOperation
927 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
928 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
929 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
930 myHasConstraintShown[PartSet_Tools::Expressions]);
934 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
936 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
937 if (!anAIS.IsNull()) {
938 bool aToUseZLayer = false;
939 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
940 if (aFeature.get() && PartSet_Tools::findRefsToMeFeature(aFeature,
941 SketchPlugin_Projection::ID()))
943 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
944 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
945 if (!aDim.IsNull()) {
948 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
952 aCtx->SetZLayer(anAIS, myVisualLayerId);
956 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
959 // it should be recomputed in order to disappear in the viewer if the corresponded object
961 //if (myCustomPrs->isActive())
962 // myCustomPrs->redisplay(theObject, false);
965 void PartSet_Module::onViewTransformed(int theTrsfType)
967 // Set length of arrows constant in pixel size
968 // if the operation is panning or rotate or panglobal then do nothing
969 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
971 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
972 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
973 if (aContext.IsNull())
976 //Handle(V3d_View) aView = aViewer->activeView();
978 XGUI_Workshop* aWorkshop = getWorkshop();
979 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
980 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
981 Handle(V3d_View) aView;
983 for (aV3dViewer->InitDefinedViews();
984 aV3dViewer->MoreDefinedViews();
985 aV3dViewer->NextDefinedViews()) {
986 Handle(V3d_View) aV = aV3dViewer->DefinedView();
987 double aS = aV->Scale();
996 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
997 if (aCurrentOperation &&
998 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
999 sketchMgr()->isNestedSketchOperation(aCurrentOperation)))
1001 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1003 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1004 SketcherPrs_Tools::setArrowSize(aLen);
1005 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1006 aViewer->SetScale(aViewer->activeView(), aCurScale);
1007 double aTextHeight = SketcherPrs_Tools::getConfigTextHeight();
1008 SketcherPrs_Tools::setTextHeight (aTextHeight);
1009 bool isModified = false;
1010 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1011 foreach (AISObjectPtr aAIS, aPrsList) {
1012 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1014 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1015 if (!aDim.IsNull()) {
1016 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1017 aDim->DimensionAspect()->TextAspect()->SetHeight(aTextHeight);
1018 aContext->Redisplay(aDim, false);
1023 aDisplayer->updateViewer();
1027 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1029 return myCustomPrs->isActive(theFlag);
1032 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1033 const ModuleBase_CustomizeFlag& theFlag,
1034 const bool theUpdateViewer)
1036 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1039 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1040 const bool theUpdateViewer)
1042 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1045 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1046 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1048 bool aCustomized = false;
1050 XGUI_Workshop* aWorkshop = getWorkshop();
1051 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1052 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1056 if (!theResult.get()) {
1057 std::vector<int> aColor;
1058 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1059 if (!aColor.empty()) {
1060 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1063 // customize dimentional constrains
1064 sketchMgr()->customizePresentation(anObject);
1069 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1070 AISObjectPtr thePrs,
1071 GeomCustomPrsPtr theCustomPrs)
1073 bool aCustomized = false;
1075 XGUI_Workshop* aWorkshop = getWorkshop();
1076 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1077 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1081 std::vector<int> aColor;
1082 bool aUseCustomColor = true;
1083 if (aUseCustomColor)
1084 myOverconstraintListener->getCustomColor(anObject, aColor);
1085 // customize sketch symbol presentation
1086 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1087 if (!anAISIO.IsNull()) {
1088 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1089 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1090 if (!aPrs.IsNull()) {
1091 aPrs->SetCustomColor(aColor);
1094 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1095 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1096 if (!aPrs.IsNull()) {
1097 aPrs->SetCustomColor(aColor);
1102 // customize sketch dimension constraint presentation
1104 if (!aColor.empty()) { // otherwise presentation has the default color
1105 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1111 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1112 const bool theUpdateViewer)
1114 bool isRedisplayed = false;
1115 if (myCustomPrs->isActive(theFlag))
1116 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1118 return isRedisplayed;
1121 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1123 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1125 QLabel* aLabel = aOB->activeDocLabel();
1126 aLabel->installEventFilter(myMenuMgr);
1127 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1128 SLOT(onActiveDocPopup(const QPoint&)));
1129 aOB->treeView()->setExpandsOnDoubleClick(false);
1130 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1131 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1133 Events_Loop* aLoop = Events_Loop::loop();
1134 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1138 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1140 SessionPtr aMgr = ModelAPI_Session::get();
1141 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1143 XGUI_Workshop* aWorkshop = getWorkshop();
1144 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1146 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1149 aMenu.addAction(aActivatePartAction);
1150 aMenu.exec(aHeader->mapToGlobal(thePnt));
1153 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1155 return mySketchMgr->createPresentation(theResult);
1159 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1162 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1164 /// If last line finished on vertex the lines creation sequence has to be break
1165 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1167 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1168 // if there is an active widget, find the presented object in it
1169 if (!anActiveWidget)
1170 anActiveWidget = aPanel->preselectionWidget();
1172 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1174 if (aWidgetValidated)
1175 anObject = aWidgetValidated->findPresentedObject(theAIS);
1181 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1183 bool aCanBeShaged = true;
1185 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1187 aCanBeShaged = false;
1189 return aCanBeShaged;
1192 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1194 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1195 int aSelected = aObjects.size();
1196 SessionPtr aMgr = ModelAPI_Session::get();
1197 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1199 bool hasResult = false;
1200 bool hasFeature = false;
1201 bool hasParameter = false;
1202 bool hasCompositeOwner = false;
1203 bool hasResultInHistory = false;
1204 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1205 hasCompositeOwner, hasResultInHistory);
1207 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1208 if (aSelected == 1) {
1209 ObjectPtr aObject = aObjects.first();
1211 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1212 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1213 bool isPart = aPart.get() ||
1214 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1216 DocumentPtr aPartDoc;
1218 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1220 if (aPart.get()) // this may be null is Part feature is disabled
1221 aPartDoc = aPart->partDoc();
1223 theMenu->addAction(aActivatePartAction);
1224 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1226 } else if (aObject->document() == aMgr->activeDocument()) {
1227 if (hasParameter || hasFeature) {
1228 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1229 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1230 if (aCurrentOp && aFeature.get()) {
1231 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1232 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1239 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1240 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1241 theMenu->addSeparator();
1244 bool aNotDeactivate = (aCurrentOp == 0);
1245 if (!aNotDeactivate) {
1246 aActivatePartAction->setEnabled(false);
1250 #define EXPAND_PARENT(OBJ) \
1251 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1252 if (aObjIndex.isValid()) { \
1253 QModelIndex aParent = aObjIndex.parent(); \
1254 int aCount = aDataModel->rowCount(aParent); \
1256 aTreeView->setExpanded(aParent, true); \
1260 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1262 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1263 // Do not change activation of parts if an operation active
1264 static QStringList aAllowActivationList;
1265 if (aAllowActivationList.isEmpty())
1266 aAllowActivationList <<
1267 QString(PartSetPlugin_Part::ID().c_str()) <<
1268 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1269 QString(PartSetPlugin_Remove::ID().c_str());
1270 if (myWorkshop->currentOperation() &&
1271 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1273 XGUI_Workshop* aWorkshop = getWorkshop();
1274 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1275 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1276 QPalette aPalet = aLabel->palette();
1278 SessionPtr aMgr = ModelAPI_Session::get();
1279 DocumentPtr aActiveDoc = aMgr->activeDocument();
1280 if (myActivePartIndex.isValid())
1281 aTreeView->setExpanded(myActivePartIndex, false);
1283 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1284 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1285 bool needUpdate = false;
1286 if (myActivePartIndex.isValid()) {
1287 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1289 aTreeView->setExpanded(myActivePartIndex, true);
1292 aLabel->setPalette(aPalet);
1293 aWorkshop->updateCommandStatus();
1295 // Update displayed objects in order to update active color
1296 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1297 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1299 foreach(ObjectPtr aObj, aObjects) {
1300 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1301 aObj->isDisabled() || (!aObj->isDisplayed());
1303 aDisplayer->redisplay(aObj, false);
1305 aDisplayer->updateViewer();
1306 // Update tree items if they are expanded
1308 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1310 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1311 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1312 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1313 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1315 ObjectPtr aConstrObj;
1316 ObjectPtr aResultObj;
1317 std::set<ObjectPtr>::const_iterator aIt;
1318 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1319 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1320 ObjectPtr aObject = (*aIt);
1321 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1322 && (aObject->document() != aRootDoc))
1323 aResultObj = aObject;
1324 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1325 && (aObject->document() != aRootDoc))
1326 aConstrObj = aObject;
1327 if (aResultObj.get() && aConstrObj.get())
1331 if (aResultObj.get() || aConstrObj.get()) {
1332 XGUI_Workshop* aWorkshop = getWorkshop();
1333 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1334 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1336 if (aResultObj.get()) {
1337 EXPAND_PARENT(aResultObj)
1339 if (aConstrObj.get()) {
1340 EXPAND_PARENT(aConstrObj)
1346 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1348 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1350 SessionPtr aMgr = ModelAPI_Session::get();
1351 if (!theIndex.isValid()) {
1352 // It seems that this code is obsolete
1353 //aMgr->setActiveDocument(aMgr->moduleDocument());
1356 if (theIndex.column() != 1) // Use only first column
1359 XGUI_Workshop* aWorkshop = getWorkshop();
1360 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1361 // De not use non editable Indexes
1362 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1364 ObjectPtr aObj = aDataModel->object(theIndex);
1366 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1367 if (!aPart.get()) { // Probably this is Feature
1368 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1369 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1370 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1373 if (aPart.get()) { // if this is a part
1374 if (aPart->partDoc() == aMgr->activeDocument()) {
1375 myMenuMgr->activatePartSet();
1377 myMenuMgr->activatePart(aPart);
1383 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1385 // z layer is created for all started operations in order to visualize operation AIS presentation
1387 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1388 if (aContext.IsNull())
1391 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1392 if (myVisualLayerId == 0) {
1393 if (myVisualLayerId == 0)
1394 aViewer->AddZLayer(myVisualLayerId);
1396 TColStd_SequenceOfInteger aZList;
1397 aViewer->GetAllZLayers(aZList);
1398 bool aFound = false;
1399 for (int i = 1; i <= aZList.Length(); i++) {
1400 if (aZList(i) == myVisualLayerId) {
1406 aViewer->AddZLayer(myVisualLayerId);
1408 // if there is an active operation with validated widget,
1409 // the filters of this widget should be activated in the created view
1410 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1412 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1413 if (anActiveWidget) {
1414 ModuleBase_WidgetSelector* aWSelector =
1415 dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1417 aWSelector->activateSelectionAndFilters(true);
1422 //******************************************************
1423 void PartSet_Module::widgetStateChanged(int thePreviousState)
1425 mySketchMgr->widgetStateChanged(thePreviousState);
1428 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1430 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1433 //******************************************************
1434 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1436 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1437 mySketchMgr->stopSketch(theOperation);
1441 //******************************************************
1442 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1444 GeomShapePtr aGeomShape;
1446 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1447 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1448 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1453 //******************************************************
1454 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1455 const GeomShapePtr& theGeomShape)
1457 AttributePtr anAttribute;
1458 GeomShapePtr aGeomShape = theGeomShape;
1459 if (!aGeomShape.get()) {
1460 // processing shape of result, e.g. sketch circle center is selected, this is a result
1461 // the geom shape is empty, the shape of result should be used
1462 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1463 if (aResult.get()) {
1464 aGeomShape = aResult->shape();
1468 if (aGeomShape.get()) {
1469 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1470 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1471 mySketchMgr->activeSketch());
1476 //******************************************************
1477 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1479 return sketchReentranceMgr()->reentrantMessage();
1482 //******************************************************
1483 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1485 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1488 //******************************************************
1489 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1492 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1496 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1497 if (!aChoiceTitle.isEmpty()) {
1498 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1501 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1503 aPanel->setWindowTitle(aChoiceTitle);
1507 //******************************************************
1508 XGUI_Workshop* PartSet_Module::getWorkshop() const
1510 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1511 return aConnector->workshop();
1514 //******************************************************
1515 void PartSet_Module::setDefaultConstraintShown()
1517 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1518 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1519 myHasConstraintShown[PartSet_Tools::Expressions] = false;