1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_Module.h"
4 #include "PartSet_WidgetSketchLabel.h"
5 #include "PartSet_Validators.h"
6 #include "PartSet_Tools.h"
7 #include "PartSet_PreviewPlanes.h"
8 #include "PartSet_WidgetPoint2d.h"
9 #include "PartSet_WidgetPoint2dDistance.h"
10 #include "PartSet_WidgetPoint2DFlyout.h"
11 #include "PartSet_WidgetShapeSelector.h"
12 #include "PartSet_WidgetMultiSelector.h"
13 #include "PartSet_WidgetEditor.h"
14 #include "PartSet_WidgetFileSelector.h"
15 #include "PartSet_WidgetSketchCreator.h"
16 #include "PartSet_SketcherMgr.h"
17 #include "PartSet_SketcherReetntrantMgr.h"
18 #include "PartSet_ResultSketchPrs.h"
19 #include "PartSet_MenuMgr.h"
20 #include "PartSet_CustomPrs.h"
21 #include "PartSet_IconFactory.h"
22 #include "PartSet_WidgetChoice.h"
23 #include "PartSet_OverconstraintListener.h"
25 #include "PartSet_Filters.h"
26 #include "PartSet_FilterInfinite.h"
28 #include <PartSetPlugin_Remove.h>
29 #include <PartSetPlugin_Part.h>
30 #include <PartSetPlugin_Duplicate.h>
32 #include <ModuleBase_Operation.h>
33 #include <ModuleBase_OperationAction.h>
34 #include <ModuleBase_IViewer.h>
35 #include <ModuleBase_IViewWindow.h>
36 #include <ModuleBase_IPropertyPanel.h>
37 #include <ModuleBase_WidgetEditor.h>
38 #include <ModuleBase_WidgetValidated.h>
39 #include <ModuleBase_FilterFactory.h>
40 #include <ModuleBase_Tools.h>
41 #include <ModuleBase_OperationFeature.h>
42 #include <ModuleBase_WidgetFactory.h>
43 #include <ModuleBase_OperationDescription.h>
44 #include <ModuleBase_ViewerPrs.h>
46 #include <ModelAPI_Object.h>
47 #include <ModelAPI_Events.h>
48 #include <ModelAPI_Validator.h>
49 #include <ModelAPI_Data.h>
50 #include <ModelAPI_Session.h>
51 #include <ModelAPI_ResultBody.h>
52 #include <ModelAPI_AttributeString.h>
53 #include <ModelAPI_AttributeSelectionList.h>
55 #include <GeomDataAPI_Point2D.h>
56 #include <GeomDataAPI_Point.h>
57 #include <GeomDataAPI_Dir.h>
59 #include <XGUI_Displayer.h>
60 #include <XGUI_Workshop.h>
61 #include <XGUI_OperationMgr.h>
62 #include <XGUI_PropertyPanel.h>
63 #include <XGUI_ModuleConnector.h>
64 #include <XGUI_ContextMenuMgr.h>
65 #include <XGUI_Tools.h>
66 #include <XGUI_ObjectsBrowser.h>
67 #include <XGUI_SelectionMgr.h>
68 #include <XGUI_DataModel.h>
69 #include <XGUI_ErrorMgr.h>
70 #include <XGUI_CustomPrs.h>
71 #include <XGUI_SelectionMgr.h>
73 #include <SketchPlugin_Feature.h>
74 #include <SketchPlugin_Sketch.h>
75 #include <SketchPlugin_ConstraintAngle.h>
76 #include <SketchPlugin_ConstraintLength.h>
77 #include <SketchPlugin_ConstraintDistance.h>
78 #include <SketchPlugin_ConstraintParallel.h>
79 #include <SketchPlugin_ConstraintPerpendicular.h>
80 #include <SketchPlugin_ConstraintRadius.h>
82 #include <SketcherPrs_SymbolPrs.h>
83 #include <SketcherPrs_Tools.h>
85 #include <Events_Loop.h>
86 #include <Config_PropManager.h>
87 #include <Config_Keywords.h>
89 #include <StdSelect_TypeOfFace.hxx>
90 #include <TopoDS_Vertex.hxx>
92 #include <TopoDS_Shape.hxx>
93 #include <BRep_Tool.hxx>
94 #include <AIS_Dimension.hxx>
97 #include <QMouseEvent>
100 #include <QApplication>
101 #include <QMessageBox>
102 #include <QMainWindow>
106 #include <GeomAlgoAPI_FaceBuilder.h>
107 #include <GeomDataAPI_Dir.h>
109 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
115 /*!Create and return new instance of XGUI_Module*/
116 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
118 return new PartSet_Module(theWshop);
121 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
122 : ModuleBase_IModule(theWshop),
125 new PartSet_IconFactory();
127 mySketchMgr = new PartSet_SketcherMgr(this);
128 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
130 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
131 XGUI_Workshop* aWorkshop = aConnector->workshop();
133 ModuleBase_IViewer* aViewer = theWshop->viewer();
134 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
135 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
136 connect(aViewer, SIGNAL(viewTransformed(int)),
137 SLOT(onViewTransformed(int)));
138 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
139 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
140 myMenuMgr = new PartSet_MenuMgr(this);
141 myCustomPrs = new PartSet_CustomPrs(theWshop);
143 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
145 Events_Loop* aLoop = Events_Loop::loop();
146 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
148 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
149 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
151 setDefaultConstraintShown();
153 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
154 "Reference shape wireframe color in operation", Config_Prop::Color,
155 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
156 Config_PropManager::registerProp("Visualization", "operation_result_color",
157 "Result shape wireframe color in operation", Config_Prop::Color,
158 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
159 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
160 "Multi selector item color in operation", Config_Prop::Color,
161 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
164 PartSet_Module::~PartSet_Module()
166 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
167 for (; aIt.More(); aIt.Next()) {
168 Handle(SelectMgr_Filter) aFilter = aIt.Value();
169 if (!aFilter.IsNull())
173 delete myOverconstraintListener;
176 void PartSet_Module::activateSelectionFilters()
178 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
179 for (; aIt.More(); aIt.Next()) {
180 Handle(SelectMgr_Filter) aFilter = aIt.Value();
181 if (!aFilter.IsNull())
182 myWorkshop->viewer()->addSelectionFilter(aFilter);
186 void PartSet_Module::deactivateSelectionFilters()
188 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
189 for (; aIt.More(); aIt.Next()) {
190 Handle(SelectMgr_Filter) aFilter = aIt.Value();
191 if (!aFilter.IsNull())
192 myWorkshop->viewer()->removeSelectionFilter(aFilter);
196 void PartSet_Module::storeSelection()
198 sketchMgr()->storeSelection();
201 void PartSet_Module::restoreSelection()
203 sketchMgr()->restoreSelection();
206 void PartSet_Module::registerValidators()
208 //Registering of validators
209 SessionPtr aMgr = ModelAPI_Session::get();
210 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
211 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
212 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
213 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
214 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
215 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
216 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
217 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
218 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
219 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
220 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
221 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
222 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
223 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
224 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
225 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
226 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
229 void PartSet_Module::registerFilters()
231 //Registering of selection filters
232 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
233 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
236 void PartSet_Module::registerProperties()
238 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
240 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
241 Config_Prop::Integer, SKETCH_WIDTH);
242 Config_PropManager::registerProp("Sketch planes", "rotate_to_plane", "Rotate to plane when selected",
243 Config_Prop::Boolean, "false");
246 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
248 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
251 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
253 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
254 mySketchMgr->commitNestedSketch(theOperation);
257 /// Restart sketcher operations automatically
258 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
260 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
261 if (aFOperation && !aFOperation->isEditOperation()) {
262 // the selection is cleared after commit the create operation
263 // in order to do not use the same selected objects in the restarted operation
264 // for common behaviour, the selection is cleared even if the operation is not restarted
265 getWorkshop()->selector()->clearSelection();
270 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
272 /// Restart sketcher operations automatically
273 mySketchReentrantMgr->operationAborted(theOperation);
276 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
278 ModuleBase_IWorkshop* anIWorkshop = workshop();
279 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
280 anIWorkshop->updateCommandStatus();
283 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
286 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(anIWorkshop);
287 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
288 ModuleBase_ModelWidget* aFilledWidget = 0;
289 bool aPostonedWidgetActivation = false;
290 FeaturePtr aFeature = aFOperation->feature();
292 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(anIWorkshop, aFeature);
293 // if there is a greed attribute, automatic commit by preselection for this feature is prohibited
294 aWorkshop->setPropertyPanel(aFOperation);
296 // filling the operation values by the current selection
297 // if the operation can be committed after the controls filling, the method perform should
298 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
299 bool isOperationCommitted = false;
300 if (!aFOperation->isEditOperation()) {
301 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
302 if (currentOperation() != aFOperation)
303 isOperationCommitted = true;
305 if (aGreedAttributeId.empty()) {
306 // a signal should be emitted before the next widget activation
307 // because, the activation of the next widget will give a focus to the widget. As a result
308 // the value of the widget is initialized. And commit may happens until the value is entered.
310 if (mySketchReentrantMgr->canBeCommittedByPreselection())
311 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
312 // activate the next obligatory widget
313 if (!isOperationCommitted)
314 aPropertyPanel->activateNextWidget(aFilledWidget);
317 else { // there is a greed widget
318 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
319 std::string aFirstAttributeId = aWidgets.front()->attributeID();
320 // activate next widget after greeded if it is the first widget in the panel
321 // else the first panel widget is already activated by operation start
322 if (aFirstAttributeId == aGreedAttributeId)
323 aPostonedWidgetActivation = true;
326 } if (!isOperationCommitted) {
327 anIWorkshop->updateCommandStatus();
328 aWorkshop->connectToPropertyPanel(true);
329 operationStartedInternal(aFOperation);
331 // the objects of the current operation should be deactivated
332 QObjectPtrList anObjects;
333 anObjects.append(aFeature);
334 std::list<ResultPtr> aResults = aFeature->results();
335 std::list<ResultPtr>::const_iterator aIt;
336 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
337 anObjects.append(*aIt);
339 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
340 for (; anIt != aLast; anIt++)
341 aWorkshop->deactivateActiveObject(*anIt, false);
342 if (anObjects.size() > 0) {
343 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
344 aDisplayer->updateViewer();
347 if (aPostonedWidgetActivation) {
348 // if the widget is an empty in the chain of activated widgets, the current operation
349 // is restarted. It should be performed after functionality of the operation starting
350 aPropertyPanel->activateNextWidget(aFilledWidget);
356 void PartSet_Module::operationStartedInternal(ModuleBase_Operation* theOperation)
358 /// Restart sketcher operations automatically
359 mySketchReentrantMgr->operationStarted(theOperation);
361 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
362 mySketchMgr->startSketch(theOperation);
364 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
365 mySketchMgr->startNestedSketch(theOperation);
368 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
370 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
371 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
375 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
377 ModuleBase_IModule::operationResumed(theOperation);
379 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
381 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
382 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
386 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
388 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
389 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
390 bool isModified = isModifiedArgs || isModifiedResults;
392 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
393 mySketchMgr->stopNestedSketch(theOperation);
395 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
396 setDefaultConstraintShown();
398 //VSV: Viewer is updated on feature update and redisplay
400 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
401 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
402 aDisplayer->updateViewer();
405 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
406 aLast = myHasConstraintShown.end();
407 for (; anIt != aLast; anIt++) {
408 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
412 ModuleBase_Operation* PartSet_Module::currentOperation() const
414 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
415 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
416 return anOpMgr->currentOperation();
419 bool PartSet_Module::canUndo() const
421 bool aCanUndo = false;
422 SessionPtr aMgr = ModelAPI_Session::get();
423 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
424 aCanUndo = !aMgr->isOperation();
425 if (!aCanUndo) // check the enable state additionally by sketch manager
426 aCanUndo = aMgr->canUndo();
431 bool PartSet_Module::canRedo() const
433 bool aCanRedo = false;
434 SessionPtr aMgr = ModelAPI_Session::get();
435 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
436 aCanRedo = !aMgr->isOperation();
437 if (!aCanRedo) // check the enable state additionally by sketch manager
438 aCanRedo = aMgr->canRedo();
443 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
446 if (theActionId == "MOVE_CMD") {
447 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
449 // part features can not be moved in the history.
450 if (aFeature->getKind() == PartSetPlugin_Part::ID())
457 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
459 // the sketch manager put the restriction to the objects erase
460 return mySketchMgr->canEraseObject(theObject);
463 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
465 // the sketch manager put the restriction to the objects display
466 return mySketchMgr->canDisplayObject(theObject);
469 void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
471 mySketchMgr->processHiddenObject(theObjects);
474 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
476 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
478 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
479 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
480 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
481 if (isSketchOp || isNestedOp) {
482 // in active sketch operation it is possible to activate operation object in selection
483 // in the edit operation, e.g. points of the line can be moved when the line is edited
484 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
485 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
490 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
492 QMap<int, QAction*>& theMenuActions) const
494 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
497 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
499 myMenuMgr->updateViewerMenu(theStdActions);
502 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
504 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
505 if (anError.isEmpty())
506 anError = sketchMgr()->getFeatureError(theFeature);
511 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
512 QStringList& theIds) const
514 myMenuMgr->grantedOperationIds(theOperation, theIds);
516 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
517 XGUI_Workshop* aWorkshop = getWorkshop();
518 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
522 void PartSet_Module::activeSelectionModes(QIntList& theModes)
525 if (mySketchMgr->activeSketch().get())
526 PartSet_SketcherMgr::sketchSelectionModes(theModes);
529 bool PartSet_Module::isMouseOverWindow()
531 return mySketchMgr->isMouseOverWindow();
534 void PartSet_Module::closeDocument()
539 void PartSet_Module::clearViewer()
541 myCustomPrs->clearPrs();
543 XGUI_Workshop* aWorkshop = getWorkshop();
544 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
545 aDisplayer->deactivateSelectionFilters();
548 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
550 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
554 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
555 // we have to manually activate the sketch label in edit mode
556 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
557 aPanel->activateWidget(aPanel->modelWidgets().first());
560 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
561 QList<ModuleBase_ModelWidget*>& theWidgets) const
563 bool aProcessed = false;
565 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
566 XGUI_Workshop* aWorkshop = getWorkshop();
567 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
568 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
569 ModuleBase_ISelection* aSelection = workshop()->selection();
570 // click on a point in sketch leads here with the point is highlighted, not yet selected
571 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
572 if (aPreselection.size() == 1) {
573 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
574 ObjectPtr anObject = aSelectedPrs->object();
576 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
577 FeaturePtr anOpFeature = aFOperation->feature();
578 GeomShapePtr aShape = aSelectedPrs->shape();
579 // click on the digit of dimension constrain comes here with an empty shape, so we need the check
580 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
581 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
582 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
583 mySketchMgr->activeSketch());
584 if (anAttribute.get()) {
585 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
586 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
588 const std::string anAttributeId = anAttribute->id();
589 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
591 theWidgets = aFactory.getModelWidgets();
592 // it is possible that the point does not present in XML definition,
593 // in this case, we assume that it is not processed by this module
594 // e.g. "Intersection point" feature
595 aProcessed = !theWidgets.isEmpty();
603 void PartSet_Module::onSelectionChanged()
605 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
609 bool isSketcherOp = false;
610 // An edit operation is enable only if the current opeation is the sketch operation
611 if (mySketchMgr->activeSketch()) {
612 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
613 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
616 // Editing of constraints can be done on selection
617 ModuleBase_ISelection* aSelect = myWorkshop->selection();
618 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
619 if (aSelected.size() == 1) {
620 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
621 ObjectPtr aObject = aPrs->object();
622 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
624 std::string aId = aFeature->getKind();
625 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
626 (aId == SketchPlugin_ConstraintLength::ID()) ||
627 (aId == SketchPlugin_ConstraintDistance::ID()) ||
628 (aId == SketchPlugin_ConstraintAngle::ID())) {
629 editFeature(aFeature);
636 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
638 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
639 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
640 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
643 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
645 Config_WidgetAPI* theWidgetApi)
647 ModuleBase_IWorkshop* aWorkshop = workshop();
648 XGUI_Workshop* aXUIWorkshop = getWorkshop();
649 ModuleBase_ModelWidget* aWgt = NULL;
650 if (theType == "sketch-start-label") {
651 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
652 theWidgetApi, myHasConstraintShown);
653 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
654 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
655 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
656 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
658 } else if (theType == "sketch-2dpoint_selector") {
659 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
661 aPointWgt->setSketch(mySketchMgr->activeSketch());
662 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
664 }else if (theType == "sketch-2dpoint_flyout_selector") {
665 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
667 aPointWgt->setSketch(mySketchMgr->activeSketch());
668 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
670 } else if (theType == "point2ddistance") {
671 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
672 aWorkshop, theWidgetApi);
673 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
675 } else if (theType == "sketch_shape_selector") {
676 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
677 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
678 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
679 aWgt = aShapeSelectorWgt;
680 } else if (theType == "sketch_multi_selector") {
681 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
682 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
683 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
684 aWgt = aShapeSelectorWgt;
686 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
687 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
688 } else if (theType == "export_file_selector") {
689 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
690 } else if (theType == "sketch_launcher") {
691 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
692 } else if (theType == "module_choice") {
693 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
694 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
695 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
700 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
702 ModuleBase_ModelWidget* anActiveWidget = 0;
704 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
705 if (!anActiveWidget) {
706 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
708 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
709 anActiveWidget = aPanel->activeWidget();
712 return anActiveWidget;
715 bool PartSet_Module::deleteObjects()
717 bool isProcessed = false;
719 XGUI_Workshop* aWorkshop = getWorkshop();
720 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
722 //SessionPtr aMgr = ModelAPI_Session::get();
723 // 1. check whether the delete should be processed in the module
724 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
725 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
726 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
727 if (isSketchOp || isNestedOp) {
729 // 2. find selected presentations
730 // selected objects should be collected before the current operation abort because
731 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
732 ModuleBase_ISelection* aSel = workshop()->selection();
733 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
734 // if there are no selected objects in the viewer, that means that the selection in another
735 // place cased this method. It is necessary to return the false value to understande in above
736 // method that delete is not processed
737 if (aSelectedObj.count() == 0)
740 // avoid delete of the objects, which are not belong to the current sketch
741 // in order to do not delete results of other sketches
742 QObjectPtrList aSketchObjects;
743 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
744 for ( ; anIt != aLast; anIt++) {
745 ObjectPtr anObject = *anIt;
746 if (mySketchMgr->isObjectOfSketch(anObject)) {
747 // sketch feature should be used in this list because workshop deletes features only
748 // results are skipped
749 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
750 aSketchObjects.append(aSketchFeature);
753 // if the selection contains only local selected presentations from other sketches,
754 // the Delete operation should not be done at all
755 if (aSketchObjects.size() == 0)
758 // 3. start operation
759 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
760 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
762 // the active nested sketch operation should be aborted unconditionally
763 // the Delete action should be additionally granted for the Sketch operation
764 // in order to do not abort/commit it
765 if (!anOpMgr->canStartOperation(anOpAction->id()))
766 return true; // the objects are processed but can not be deleted
768 anOpMgr->startOperation(anOpAction);
770 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
771 // the problem is in AIS Dimensions recompute if a line and the dim are removed, line is the first
772 // it causes the AIS recompute, where the base line is null, the result is empty AIS in the viewer
773 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
775 // 4. delete features
776 // sketch feature should be skipped, only sub-features can be removed
777 // when sketch operation is active
778 aWorkshop->deleteFeatures(aSketchObjects);
780 anOpMgr->commitOperation();
785 void PartSet_Module::onFeatureTriggered()
787 QAction* aCmd = dynamic_cast<QAction*>(sender());
788 if (aCmd->isCheckable() && aCmd->isChecked()) {
789 // 1. check whether the delete should be processed in the module
790 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
791 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
793 // in case if in the viewer nothing is displayed, the create operation should not be
794 // comitted even if all values of the feature are initialized
795 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
796 // the action information should be saved before the operation is aborted
797 // because this abort leads to update command status, which unchecks this action
798 anOperation->abort();
799 launchOperation(aCmd->data().toString());
803 ModuleBase_IModule::onFeatureTriggered();
806 void PartSet_Module::editFeature(FeaturePtr theFeature)
808 storeConstraintsState(theFeature->getKind());
809 ModuleBase_IModule::editFeature(theFeature);
812 bool PartSet_Module::canCommitOperation() const
817 void PartSet_Module::launchOperation(const QString& theCmdId)
819 storeConstraintsState(theCmdId.toStdString());
820 ModuleBase_IModule::launchOperation(theCmdId);
823 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
825 if (myWorkshop->currentOperation() &&
826 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
827 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
828 mySketchMgr->showConstraintStates();
829 myHasConstraintShown = aShownStates;
831 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str())) {
832 // Show constraints if a constraint was anOperation
833 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
834 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
835 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
836 myHasConstraintShown[PartSet_Tools::Expressions]);
840 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
842 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
843 if (!anAIS.IsNull()) {
844 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
845 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
846 if (!aDim.IsNull()) {
847 aCtx->SetZLayer(aDim, myVisualLayerId);
849 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
851 aCtx->SetZLayer(aCons, myVisualLayerId);
856 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
859 // it should be recomputed in order to disappear in the viewer if the corresponded object
861 //if (myCustomPrs->isActive())
862 // myCustomPrs->redisplay(theObject, false);
865 void PartSet_Module::onViewTransformed(int theTrsfType)
867 // Set length of arrows constant in pixel size
868 // if the operation is panning or rotate or panglobal then do nothing
869 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
871 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
872 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
873 if (aContext.IsNull())
876 //Handle(V3d_View) aView = aViewer->activeView();
878 XGUI_Workshop* aWorkshop = getWorkshop();
879 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
880 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
881 Handle(V3d_View) aView;
883 for (aV3dViewer->InitDefinedViews();
884 aV3dViewer->MoreDefinedViews();
885 aV3dViewer->NextDefinedViews()) {
886 Handle(V3d_View) aV = aV3dViewer->DefinedView();
887 double aS = aV->Scale();
895 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
897 double aPrevLen = SketcherPrs_Tools::getArrowSize();
898 SketcherPrs_Tools::setArrowSize(aLen);
899 const double aPrevScale = aViewer->Scale(aViewer->activeView());
900 const double aCurScale = aViewer->activeView()->Camera()->Scale();
901 aViewer->SetScale(aViewer->activeView(), aCurScale);
902 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
903 bool isModified = false;
904 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
905 foreach (AISObjectPtr aAIS, aPrsList) {
906 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
908 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
909 if (!aDim.IsNull()) {
910 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
911 aContext->Redisplay(aDim, false);
916 aDisplayer->updateViewer();
919 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature, const ModuleBase_CustomizeFlag& theFlag,
920 const bool theUpdateViewer)
922 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
925 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
926 const bool theUpdateViewer)
928 myCustomPrs->deactivate(theFlag, theUpdateViewer);
931 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
932 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
934 bool aCustomized = false;
939 XGUI_Workshop* aWorkshop = getWorkshop();
940 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
941 ObjectPtr anObject = aDisplayer->getObject(thePrs);
942 if (anObject.get()) {
943 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
944 // customize sketch symbol presentation
946 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
947 if (!anAISIO.IsNull()) {
948 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
949 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
950 if (!aPrs.IsNull()) {
951 std::vector<int> aColor;
952 myOverconstraintListener->getConflictingColor(aColor);
953 aPrs->SetConflictingConstraint(isConflicting, aColor);
959 // customize sketch dimension constraint presentation
961 std::vector<int> aColor;
963 myOverconstraintListener->getConflictingColor(aColor);
966 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
967 if (!aColor.empty()) {
968 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
972 // customize dimentional constrains
973 sketchMgr()->customizePresentation(anObject);
979 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
980 const bool theUpdateViewer)
982 bool isRedisplayed = false;
983 if (myCustomPrs->isActive(theFlag))
984 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
986 return isRedisplayed;
989 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
991 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
993 QLabel* aLabel = aOB->activeDocLabel();
994 aLabel->installEventFilter(myMenuMgr);
995 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
996 SLOT(onActiveDocPopup(const QPoint&)));
997 //QPalette aPalet = aLabel->palette();
998 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
999 //aLabel->setPalette(aPalet);
1000 aOB->treeView()->setExpandsOnDoubleClick(false);
1001 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1002 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1006 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1008 SessionPtr aMgr = ModelAPI_Session::get();
1009 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1011 XGUI_Workshop* aWorkshop = getWorkshop();
1012 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1014 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1017 aMenu.addAction(aActivatePartAction);
1018 aMenu.exec(aHeader->mapToGlobal(thePnt));
1021 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1023 return mySketchMgr->createPresentation(theResult);
1027 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1030 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1032 /// If last line finished on vertex the lines creation sequence has to be break
1033 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1035 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1036 // if there is an active widget, find the presented object in it
1037 if (!anActiveWidget)
1038 anActiveWidget = aPanel->preselectionWidget();
1040 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1042 if (aWidgetValidated)
1043 anObject = aWidgetValidated->findPresentedObject(theAIS);
1049 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1051 bool aCanBeShaged = true;
1053 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1055 aCanBeShaged = false;
1057 return aCanBeShaged;
1060 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1062 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1063 int aSelected = aObjects.size();
1064 SessionPtr aMgr = ModelAPI_Session::get();
1065 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1067 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1068 if (aSelected == 1) {
1069 bool hasResult = false;
1070 bool hasFeature = false;
1071 bool hasParameter = false;
1072 bool hasCompositeOwner = false;
1073 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1075 ObjectPtr aObject = aObjects.first();
1077 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1078 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1079 bool isPart = aPart.get() ||
1080 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1082 DocumentPtr aPartDoc;
1084 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1086 if (aPart.get()) // this may be null is Part feature is disabled
1087 aPartDoc = aPart->partDoc();
1089 theMenu->addAction(aActivatePartAction);
1090 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1092 } else if (aObject->document() == aMgr->activeDocument()) {
1093 if (hasParameter || hasFeature) {
1094 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1095 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1096 if (aCurrentOp && aFeature.get()) {
1097 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1098 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1103 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1105 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
1108 bool aNotDeactivate = (aCurrentOp == 0);
1109 if (!aNotDeactivate) {
1110 aActivatePartAction->setEnabled(false);
1114 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1116 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1117 // Do not change activation of parts if an operation active
1118 static QStringList aAllowActivationList;
1119 if (aAllowActivationList.isEmpty())
1120 aAllowActivationList <<
1121 QString(PartSetPlugin_Part::ID().c_str()) <<
1122 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1123 QString(PartSetPlugin_Remove::ID().c_str());
1124 if (myWorkshop->currentOperation() &&
1125 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1127 XGUI_Workshop* aWorkshop = getWorkshop();
1128 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1129 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1130 QPalette aPalet = aLabel->palette();
1132 SessionPtr aMgr = ModelAPI_Session::get();
1133 DocumentPtr aActiveDoc = aMgr->activeDocument();
1134 if (aActivePartIndex.isValid())
1135 aTreeView->setExpanded(aActivePartIndex, false);
1136 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1137 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1138 if (aActivePartIndex.isValid())
1139 aTreeView->setExpanded(aActivePartIndex, true);
1141 aLabel->setPalette(aPalet);
1142 aWorkshop->updateCommandStatus();
1144 // Update displayed objects in order to update active color
1145 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1146 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1148 foreach(ObjectPtr aObj, aObjects) {
1149 //TODO: replace by redisplay event.
1150 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1151 aObj->isDisabled() || (!aObj->isDisplayed());
1153 aDisplayer->redisplay(aObj, false);
1155 aDisplayer->updateViewer();
1159 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1161 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1163 SessionPtr aMgr = ModelAPI_Session::get();
1164 if (!theIndex.isValid()) {
1165 aMgr->setActiveDocument(aMgr->moduleDocument());
1168 if (theIndex.column() != 0) // Use only first column
1171 XGUI_Workshop* aWorkshop = getWorkshop();
1172 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1173 // De not use non editable Indexes
1174 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1176 ObjectPtr aObj = aDataModel->object(theIndex);
1178 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1179 if (!aPart.get()) { // Probably this is Feature
1180 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1181 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1182 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1185 if (aPart.get()) { // if this is a part
1186 if (aPart->partDoc() == aMgr->activeDocument()) {
1187 myMenuMgr->activatePartSet();
1195 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1197 // z layer is created for all started operations in order to visualize operation AIS presentation
1199 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1200 if (aContext.IsNull())
1203 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1204 if (myVisualLayerId == 0) {
1205 if (myVisualLayerId == 0)
1206 aViewer->AddZLayer(myVisualLayerId);
1208 TColStd_SequenceOfInteger aZList;
1209 aViewer->GetAllZLayers(aZList);
1210 bool aFound = false;
1211 for (int i = 1; i <= aZList.Length(); i++) {
1212 if (aZList(i) == myVisualLayerId) {
1218 aViewer->AddZLayer(myVisualLayerId);
1220 // if there is an active operation with validated widget,
1221 // the filters of this widget should be activated in the created view
1222 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1224 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1225 if (anActiveWidget) {
1226 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1228 aWSelector->activateSelectionAndFilters(true);
1233 //******************************************************
1234 void PartSet_Module::widgetStateChanged(int thePreviousState)
1236 mySketchMgr->widgetStateChanged(thePreviousState);
1239 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1241 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1244 //******************************************************
1245 void PartSet_Module::beforeOperationStarted(ModuleBase_Operation* theOperation)
1249 //******************************************************
1250 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1252 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1253 mySketchMgr->stopSketch(theOperation);
1257 //******************************************************
1258 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1260 GeomShapePtr aGeomShape;
1262 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1263 if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1264 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1269 //******************************************************
1270 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1271 const GeomShapePtr& theGeomShape)
1273 AttributePtr anAttribute;
1274 GeomShapePtr aGeomShape = theGeomShape;
1275 if (!aGeomShape.get()) {
1276 // processing shape of result, e.g. sketch circle center is selected, this is a result
1277 // the geom shape is empty, the shape of result should be used
1278 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1279 if (aResult.get()) {
1280 aGeomShape = aResult->shape();
1284 if (aGeomShape.get()) {
1285 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1286 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1287 mySketchMgr->activeSketch());
1292 //******************************************************
1293 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1296 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1300 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1301 if (!aChoiceTitle.isEmpty()) {
1302 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1305 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1307 aPanel->setWindowTitle(aChoiceTitle);
1311 //******************************************************
1312 XGUI_Workshop* PartSet_Module::getWorkshop() const
1314 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1315 return aConnector->workshop();
1318 //******************************************************
1319 void PartSet_Module::setDefaultConstraintShown()
1321 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1322 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1323 myHasConstraintShown[PartSet_Tools::Expressions] = false;