1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_Module.h"
4 #include "PartSet_WidgetSketchLabel.h"
5 #include "PartSet_Validators.h"
6 #include "PartSet_Tools.h"
7 #include "PartSet_WidgetPoint2d.h"
8 #include "PartSet_WidgetPoint2dDistance.h"
9 #include "PartSet_WidgetPoint2DFlyout.h"
10 #include "PartSet_WidgetShapeSelector.h"
11 #include "PartSet_WidgetMultiSelector.h"
12 #include "PartSet_WidgetEditor.h"
13 #include "PartSet_WidgetFileSelector.h"
14 #include "PartSet_WidgetSketchCreator.h"
15 #include "PartSet_SketcherMgr.h"
16 #include "PartSet_SketcherReetntrantMgr.h"
17 #include "PartSet_MenuMgr.h"
18 #include "PartSet_CustomPrs.h"
19 #include "PartSet_IconFactory.h"
20 #include "PartSet_WidgetChoice.h"
21 #include "PartSet_OverconstraintListener.h"
23 #include "PartSet_Filters.h"
24 #include "PartSet_FilterInfinite.h"
26 #include <PartSetPlugin_Remove.h>
27 #include <PartSetPlugin_Part.h>
28 #include <PartSetPlugin_Duplicate.h>
30 #include <ModuleBase_Operation.h>
31 #include <ModuleBase_OperationAction.h>
32 #include <ModuleBase_IViewer.h>
33 #include <ModuleBase_IViewWindow.h>
34 #include <ModuleBase_IPropertyPanel.h>
35 #include <ModuleBase_WidgetEditor.h>
36 #include <ModuleBase_WidgetValidated.h>
37 #include <ModuleBase_FilterFactory.h>
38 #include <ModuleBase_Tools.h>
39 #include <ModuleBase_OperationFeature.h>
40 #include <ModuleBase_WidgetFactory.h>
41 #include <ModuleBase_OperationDescription.h>
43 #include <ModelAPI_Object.h>
44 #include <ModelAPI_Events.h>
45 #include <ModelAPI_Validator.h>
46 #include <ModelAPI_Data.h>
47 #include <ModelAPI_Session.h>
48 #include <ModelAPI_ResultBody.h>
49 #include <ModelAPI_AttributeString.h>
51 #include <GeomDataAPI_Point2D.h>
52 #include <GeomDataAPI_Point.h>
53 #include <GeomDataAPI_Dir.h>
55 #include <XGUI_Displayer.h>
56 #include <XGUI_Workshop.h>
57 #include <XGUI_OperationMgr.h>
58 #include <XGUI_PropertyPanel.h>
59 #include <XGUI_ModuleConnector.h>
60 #include <XGUI_ContextMenuMgr.h>
61 #include <XGUI_Tools.h>
62 #include <XGUI_ObjectsBrowser.h>
63 #include <XGUI_SelectionMgr.h>
64 #include <XGUI_DataModel.h>
65 #include <XGUI_ErrorMgr.h>
66 #include <XGUI_CustomPrs.h>
68 #include <SketchPlugin_Feature.h>
69 #include <SketchPlugin_Sketch.h>
70 #include <SketchPlugin_ConstraintAngle.h>
71 #include <SketchPlugin_ConstraintLength.h>
72 #include <SketchPlugin_ConstraintDistance.h>
73 #include <SketchPlugin_ConstraintParallel.h>
74 #include <SketchPlugin_ConstraintPerpendicular.h>
75 #include <SketchPlugin_ConstraintRadius.h>
77 #include <SketcherPrs_SymbolPrs.h>
78 #include <SketcherPrs_Tools.h>
80 #include <Events_Loop.h>
81 #include <Config_PropManager.h>
82 #include <Config_Keywords.h>
84 #include <StdSelect_TypeOfFace.hxx>
85 #include <TopoDS_Vertex.hxx>
87 #include <TopoDS_Shape.hxx>
88 #include <BRep_Tool.hxx>
89 #include <AIS_Dimension.hxx>
92 #include <QMouseEvent>
95 #include <QApplication>
96 #include <QMessageBox>
97 #include <QMainWindow>
101 #include <GeomAlgoAPI_FaceBuilder.h>
102 #include <GeomDataAPI_Dir.h>
104 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
110 /*!Create and return new instance of XGUI_Module*/
111 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
113 return new PartSet_Module(theWshop);
116 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
117 : ModuleBase_IModule(theWshop),
120 new PartSet_IconFactory();
122 mySketchMgr = new PartSet_SketcherMgr(this);
123 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
125 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
126 XGUI_Workshop* aWorkshop = aConnector->workshop();
128 ModuleBase_IViewer* aViewer = theWshop->viewer();
129 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
130 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
131 connect(aViewer, SIGNAL(viewTransformed(int)),
132 SLOT(onViewTransformed(int)));
133 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
134 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
135 myMenuMgr = new PartSet_MenuMgr(this);
136 myCustomPrs = new PartSet_CustomPrs(theWshop);
138 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
140 Events_Loop* aLoop = Events_Loop::loop();
141 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
143 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
144 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
146 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
147 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
148 myHasConstraintShown[PartSet_Tools::Expressions] = false;
150 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
151 "Reference shape wireframe color in operation", Config_Prop::Color,
152 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
153 Config_PropManager::registerProp("Visualization", "operation_result_color",
154 "Result shape wireframe color in operation", Config_Prop::Color,
155 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
156 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
157 "Multi selector item color in operation", Config_Prop::Color,
158 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
161 PartSet_Module::~PartSet_Module()
163 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
164 for (; aIt.More(); aIt.Next()) {
165 Handle(SelectMgr_Filter) aFilter = aIt.Value();
166 if (!aFilter.IsNull())
170 delete myOverconstraintListener;
173 void PartSet_Module::activateSelectionFilters()
175 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
176 for (; aIt.More(); aIt.Next()) {
177 Handle(SelectMgr_Filter) aFilter = aIt.Value();
178 if (!aFilter.IsNull())
179 myWorkshop->viewer()->addSelectionFilter(aFilter);
183 void PartSet_Module::deactivateSelectionFilters()
185 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
186 for (; aIt.More(); aIt.Next()) {
187 Handle(SelectMgr_Filter) aFilter = aIt.Value();
188 if (!aFilter.IsNull())
189 myWorkshop->viewer()->removeSelectionFilter(aFilter);
193 void PartSet_Module::storeSelection()
195 sketchMgr()->storeSelection();
198 void PartSet_Module::restoreSelection()
200 sketchMgr()->restoreSelection();
203 void PartSet_Module::registerValidators()
205 //Registering of validators
206 SessionPtr aMgr = ModelAPI_Session::get();
207 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
208 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
209 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
210 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
211 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
212 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
213 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
214 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
215 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
216 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
217 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
218 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
219 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
220 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
221 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
222 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
223 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
224 aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator);
227 void PartSet_Module::registerFilters()
229 //Registering of selection filters
230 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
231 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
234 void PartSet_Module::registerProperties()
236 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
238 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
239 Config_Prop::Integer, SKETCH_WIDTH);
240 Config_PropManager::registerProp("Sketch planes", "rotate_to_plane", "Rotate to plane when selected",
241 Config_Prop::Boolean, "false");
244 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
246 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
249 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
251 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
252 mySketchMgr->commitNestedSketch(theOperation);
255 /// Restart sketcher operations automatically
256 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
258 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
259 if (aFOperation && !aFOperation->isEditOperation()) {
260 // the selection is cleared after commit the create operation
261 // in order to do not use the same selected objects in the restarted operation
262 // for common behaviour, the selection is cleared even if the operation is not restarted
263 getWorkshop()->selector()->clearSelection();
268 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
270 /// Restart sketcher operations automatically
271 mySketchReentrantMgr->operationAborted(theOperation);
274 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
276 ModuleBase_IWorkshop* anIWorkshop = workshop();
277 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
278 anIWorkshop->updateCommandStatus();
281 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
284 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(anIWorkshop);
285 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
286 ModuleBase_ModelWidget* aFilledWidget = 0;
287 bool aPostonedWidgetActivation = false;
288 FeaturePtr aFeature = aFOperation->feature();
290 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(anIWorkshop, aFeature);
291 // if there is a greed attribute, automatic commit by preselection for this feature is prohibited
292 aWorkshop->setPropertyPanel(aFOperation);
294 // filling the operation values by the current selection
295 // if the operation can be committed after the controls filling, the method perform should
296 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
297 bool isOperationCommitted = false;
298 if (!aFOperation->isEditOperation()) {
299 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
300 if (currentOperation() != aFOperation)
301 isOperationCommitted = true;
303 if (aGreedAttributeId.empty()) {
304 // a signal should be emitted before the next widget activation
305 // because, the activation of the next widget will give a focus to the widget. As a result
306 // the value of the widget is initialized. And commit may happens until the value is entered.
308 if (mySketchReentrantMgr->canBeCommittedByPreselection())
309 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
310 // activate the next obligatory widget
311 if (!isOperationCommitted)
312 aPropertyPanel->activateNextWidget(aFilledWidget);
315 else { // there is a greed widget
316 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
317 std::string aFirstAttributeId = aWidgets.front()->attributeID();
318 // activate next widget after greeded if it is the first widget in the panel
319 // else the first panel widget is already activated by operation start
320 if (aFirstAttributeId == aGreedAttributeId)
321 aPostonedWidgetActivation = true;
324 } if (!isOperationCommitted) {
325 anIWorkshop->updateCommandStatus();
326 aWorkshop->connectToPropertyPanel(true);
327 operationStartedInternal(aFOperation);
329 // the objects of the current operation should be deactivated
330 QObjectPtrList anObjects;
331 anObjects.append(aFeature);
332 std::list<ResultPtr> aResults = aFeature->results();
333 std::list<ResultPtr>::const_iterator aIt;
334 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
335 anObjects.append(*aIt);
337 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
338 for (; anIt != aLast; anIt++)
339 aWorkshop->deactivateActiveObject(*anIt, false);
340 if (anObjects.size() > 0) {
341 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
342 aDisplayer->updateViewer();
345 if (aPostonedWidgetActivation) {
346 // if the widget is an empty in the chain of activated widgets, the current operation
347 // is restarted. It should be performed after functionality of the operation starting
348 aPropertyPanel->activateNextWidget(aFilledWidget);
354 void PartSet_Module::operationStartedInternal(ModuleBase_Operation* theOperation)
356 /// Restart sketcher operations automatically
357 mySketchReentrantMgr->operationStarted(theOperation);
359 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
360 mySketchMgr->startSketch(theOperation);
362 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
363 mySketchMgr->startNestedSketch(theOperation);
366 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
368 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
369 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
373 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
375 ModuleBase_IModule::operationResumed(theOperation);
377 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
379 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
380 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
384 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
386 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
387 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
388 bool isModified = isModifiedArgs || isModifiedResults;
390 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
391 mySketchMgr->stopNestedSketch(theOperation);
394 //VSV: Viewer is updated on feature update and redisplay
396 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
397 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
398 aDisplayer->updateViewer();
401 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
402 aLast = myHasConstraintShown.end();
403 for (; anIt != aLast; anIt++) {
404 myHasConstraintShown[anIt.key()];
405 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
409 ModuleBase_Operation* PartSet_Module::currentOperation() const
411 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
412 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
413 return anOpMgr->currentOperation();
416 bool PartSet_Module::canUndo() const
418 bool aCanUndo = false;
419 SessionPtr aMgr = ModelAPI_Session::get();
420 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
421 aCanUndo = !aMgr->isOperation();
422 if (!aCanUndo) // check the enable state additionally by sketch manager
423 aCanUndo = aMgr->canUndo();
428 bool PartSet_Module::canRedo() const
430 bool aCanRedo = false;
431 SessionPtr aMgr = ModelAPI_Session::get();
432 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
433 aCanRedo = !aMgr->isOperation();
434 if (!aCanRedo) // check the enable state additionally by sketch manager
435 aCanRedo = aMgr->canRedo();
440 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
443 if (theActionId == "MOVE_CMD") {
444 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
446 // part features can not be moved in the history.
447 if (aFeature->getKind() == PartSetPlugin_Part::ID())
454 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
456 // the sketch manager put the restriction to the objects erase
457 return mySketchMgr->canEraseObject(theObject);
460 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
462 // the sketch manager put the restriction to the objects display
463 return mySketchMgr->canDisplayObject(theObject);
466 void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
468 mySketchMgr->processHiddenObject(theObjects);
471 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
473 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
475 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
476 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
477 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
478 if (isSketchOp || isNestedOp) {
479 // in active sketch operation it is possible to activate operation object in selection
480 // in the edit operation, e.g. points of the line can be moved when the line is edited
481 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
482 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
487 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
489 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
492 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
494 myMenuMgr->updateViewerMenu(theStdActions);
497 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
499 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
500 if (anError.isEmpty())
501 anError = sketchMgr()->getFeatureError(theFeature);
506 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
507 QStringList& theIds) const
509 myMenuMgr->grantedOperationIds(theOperation, theIds);
511 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
512 XGUI_Workshop* aWorkshop = getWorkshop();
513 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
517 void PartSet_Module::activeSelectionModes(QIntList& theModes)
520 if (mySketchMgr->activeSketch().get())
521 PartSet_SketcherMgr::sketchSelectionModes(theModes);
524 bool PartSet_Module::isMouseOverWindow()
526 return mySketchMgr->isMouseOverWindow();
529 void PartSet_Module::closeDocument()
534 void PartSet_Module::clearViewer()
536 myCustomPrs->clearPrs();
538 XGUI_Workshop* aWorkshop = getWorkshop();
539 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
540 aDisplayer->deactivateSelectionFilters();
543 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
545 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
549 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
550 // we have to manually activate the sketch label in edit mode
551 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
552 aPanel->activateWidget(aPanel->modelWidgets().first());
555 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
556 QList<ModuleBase_ModelWidget*>& theWidgets) const
558 bool aProcessed = false;
560 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
561 XGUI_Workshop* aWorkshop = getWorkshop();
562 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
563 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
564 ModuleBase_ISelection* aSelection = workshop()->selection();
565 // click on a point in sketch leads here with the point is highlighted, not yet selected
566 QList<ModuleBase_ViewerPrs> aPreselection = aSelection->getHighlighted();
567 if (aPreselection.size() == 1) {
568 ModuleBase_ViewerPrs aSelectedPrs = aPreselection[0];
569 ObjectPtr anObject = aSelectedPrs.object();
571 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
572 FeaturePtr anOpFeature = aFOperation->feature();
573 GeomShapePtr aShape = aSelectedPrs.shape();
574 // click on the digit of dimension constrain comes here with an empty shape, so we need the check
575 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
576 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
577 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
578 mySketchMgr->activeSketch());
579 if (anAttribute.get()) {
580 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
581 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
583 const std::string anAttributeId = anAttribute->id();
584 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
586 theWidgets = aFactory.getModelWidgets();
587 // it is possible that the point does not present in XML definition,
588 // in this case, we assume that it is not processed by this module
589 // e.g. "Intersection point" feature
590 aProcessed = !theWidgets.isEmpty();
598 void PartSet_Module::onSelectionChanged()
600 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
604 bool isSketcherOp = false;
605 // An edit operation is enable only if the current opeation is the sketch operation
606 if (mySketchMgr->activeSketch()) {
607 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
608 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
611 // Editing of constraints can be done on selection
612 ModuleBase_ISelection* aSelect = myWorkshop->selection();
613 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
614 if (aSelected.size() == 1) {
615 ModuleBase_ViewerPrs aPrs = aSelected.first();
616 ObjectPtr aObject = aPrs.object();
617 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
619 std::string aId = aFeature->getKind();
620 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
621 (aId == SketchPlugin_ConstraintLength::ID()) ||
622 (aId == SketchPlugin_ConstraintDistance::ID()) ||
623 (aId == SketchPlugin_ConstraintAngle::ID())) {
624 editFeature(aFeature);
631 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
633 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
634 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
635 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
638 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
640 Config_WidgetAPI* theWidgetApi)
642 ModuleBase_IWorkshop* aWorkshop = workshop();
643 XGUI_Workshop* aXUIWorkshop = getWorkshop();
644 ModuleBase_ModelWidget* aWgt = NULL;
645 if (theType == "sketch-start-label") {
646 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
647 theWidgetApi, myHasConstraintShown);
648 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
649 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
650 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
651 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
653 } else if (theType == "sketch-2dpoint_selector") {
654 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
656 aPointWgt->setSketch(mySketchMgr->activeSketch());
657 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
659 }else if (theType == "sketch-2dpoint_flyout_selector") {
660 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
662 aPointWgt->setSketch(mySketchMgr->activeSketch());
663 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
665 } else if (theType == "point2ddistance") {
666 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
667 aWorkshop, theWidgetApi);
668 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
670 } else if (theType == "sketch_shape_selector") {
671 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
672 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
673 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
674 aWgt = aShapeSelectorWgt;
675 } else if (theType == "sketch_multi_selector") {
676 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
677 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
678 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
679 aWgt = aShapeSelectorWgt;
680 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
681 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
682 } else if (theType == "export_file_selector") {
683 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
684 } else if (theType == "sketch_launcher") {
685 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
686 } else if (theType == "module_choice") {
687 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
688 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
689 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
694 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
696 ModuleBase_ModelWidget* anActiveWidget = 0;
698 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
699 if (!anActiveWidget) {
700 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
702 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
703 anActiveWidget = aPanel->activeWidget();
706 return anActiveWidget;
709 bool PartSet_Module::deleteObjects()
711 bool isProcessed = false;
713 XGUI_Workshop* aWorkshop = getWorkshop();
714 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
716 //SessionPtr aMgr = ModelAPI_Session::get();
717 // 1. check whether the delete should be processed in the module
718 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
719 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
720 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
721 if (isSketchOp || isNestedOp) {
723 // 2. find selected presentations
724 // selected objects should be collected before the current operation abort because
725 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
726 ModuleBase_ISelection* aSel = workshop()->selection();
727 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
728 // if there are no selected objects in the viewer, that means that the selection in another
729 // place cased this method. It is necessary to return the false value to understande in above
730 // method that delete is not processed
731 if (aSelectedObj.count() == 0)
734 // avoid delete of the objects, which are not belong to the current sketch
735 // in order to do not delete results of other sketches
736 QObjectPtrList aSketchObjects;
737 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
738 for ( ; anIt != aLast; anIt++) {
739 ObjectPtr anObject = *anIt;
740 if (mySketchMgr->isObjectOfSketch(anObject)) {
741 // sketch feature should be used in this list because workshop deletes features only
742 // results are skipped
743 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
744 aSketchObjects.append(aSketchFeature);
747 // if the selection contains only local selected presentations from other sketches,
748 // the Delete operation should not be done at all
749 if (aSketchObjects.size() == 0)
752 // 3. start operation
753 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
754 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
756 // the active nested sketch operation should be aborted unconditionally
757 // the Delete action should be additionally granted for the Sketch operation
758 // in order to do not abort/commit it
759 if (!anOpMgr->canStartOperation(anOpAction->id()))
760 return true; // the objects are processed but can not be deleted
762 anOpMgr->startOperation(anOpAction);
764 // 4. delete features
765 // sketch feature should be skipped, only sub-features can be removed
766 // when sketch operation is active
767 aWorkshop->deleteFeatures(aSketchObjects);
769 anOpMgr->commitOperation();
774 void PartSet_Module::onFeatureTriggered()
776 QAction* aCmd = dynamic_cast<QAction*>(sender());
777 if (aCmd->isCheckable() && aCmd->isChecked()) {
778 // 1. check whether the delete should be processed in the module
779 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
780 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
782 // in case if in the viewer nothing is displayed, the create operation should not be
783 // comitted even if all values of the feature are initialized
784 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
785 // the action information should be saved before the operation is aborted
786 // because this abort leads to update command status, which unchecks this action
787 anOperation->abort();
788 launchOperation(aCmd->data().toString());
792 ModuleBase_IModule::onFeatureTriggered();
795 void PartSet_Module::editFeature(FeaturePtr theFeature)
797 storeConstraintsState(theFeature->getKind());
798 ModuleBase_IModule::editFeature(theFeature);
801 void PartSet_Module::launchOperation(const QString& theCmdId)
803 storeConstraintsState(theCmdId.toStdString());
804 ModuleBase_IModule::launchOperation(theCmdId);
807 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
809 if (myWorkshop->currentOperation() &&
810 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
811 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
812 mySketchMgr->showConstraintStates();
813 myHasConstraintShown = aShownStates;
815 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str())) {
816 // Show constraints if a constraint was anOperation
817 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
818 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
819 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
820 myHasConstraintShown[PartSet_Tools::Expressions]);
824 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
826 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
827 if (!anAIS.IsNull()) {
828 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
829 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
830 if (!aDim.IsNull()) {
831 aCtx->SetZLayer(aDim, myVisualLayerId);
833 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
835 aCtx->SetZLayer(aCons, myVisualLayerId);
840 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
843 // it should be recomputed in order to disappear in the viewer if the corresponded object
845 //if (myCustomPrs->isActive())
846 // myCustomPrs->redisplay(theObject, false);
849 void PartSet_Module::onViewTransformed(int theTrsfType)
851 // Set length of arrows constant in pixel size
852 // if the operation is panning or rotate or panglobal then do nothing
853 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
855 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
856 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
857 if (aContext.IsNull())
860 //Handle(V3d_View) aView = aViewer->activeView();
862 XGUI_Workshop* aWorkshop = getWorkshop();
863 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
864 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
865 Handle(V3d_View) aView;
867 for (aV3dViewer->InitDefinedViews();
868 aV3dViewer->MoreDefinedViews();
869 aV3dViewer->NextDefinedViews()) {
870 Handle(V3d_View) aV = aV3dViewer->DefinedView();
871 double aS = aV->Scale();
879 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
881 double aPrevLen = SketcherPrs_Tools::getArrowSize();
882 SketcherPrs_Tools::setArrowSize(aLen);
883 const double aPrevScale = aViewer->Scale(aViewer->activeView());
884 const double aCurScale = aViewer->activeView()->Camera()->Scale();
885 aViewer->SetScale(aViewer->activeView(), aCurScale);
886 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
887 bool isModified = false;
888 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
889 foreach (AISObjectPtr aAIS, aPrsList) {
890 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
892 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
893 if (!aDim.IsNull()) {
894 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
895 aContext->Redisplay(aDim, false);
900 aDisplayer->updateViewer();
903 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature, const ModuleBase_CustomizeFlag& theFlag,
904 const bool theUpdateViewer)
906 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
909 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
910 const bool theUpdateViewer)
912 myCustomPrs->deactivate(theFlag, theUpdateViewer);
915 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
916 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
918 bool aCustomized = false;
923 XGUI_Workshop* aWorkshop = getWorkshop();
924 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
925 ObjectPtr anObject = aDisplayer->getObject(thePrs);
926 if (anObject.get()) {
927 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
928 // customize sketch symbol presentation
930 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
931 if (!anAISIO.IsNull()) {
932 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
933 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
934 if (!aPrs.IsNull()) {
935 std::vector<int> aColor;
936 myOverconstraintListener->getConflictingColor(aColor);
937 aPrs->SetConflictingConstraint(isConflicting, aColor);
943 // customize sketch dimension constraint presentation
945 std::vector<int> aColor;
947 myOverconstraintListener->getConflictingColor(aColor);
950 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
951 if (!aColor.empty()) {
952 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
957 // customize dimentional constrains
958 sketchMgr()->customizePresentation(anObject);
964 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
965 const bool theUpdateViewer)
967 bool isRedisplayed = false;
968 if (myCustomPrs->isActive(theFlag))
969 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
971 return isRedisplayed;
974 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
976 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
978 QLabel* aLabel = aOB->activeDocLabel();
979 aLabel->installEventFilter(myMenuMgr);
980 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
981 SLOT(onActiveDocPopup(const QPoint&)));
982 //QPalette aPalet = aLabel->palette();
983 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
984 //aLabel->setPalette(aPalet);
985 aOB->treeView()->setExpandsOnDoubleClick(false);
986 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
987 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
991 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
993 SessionPtr aMgr = ModelAPI_Session::get();
994 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
996 XGUI_Workshop* aWorkshop = getWorkshop();
997 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
999 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1002 aMenu.addAction(aActivatePartAction);
1003 aMenu.exec(aHeader->mapToGlobal(thePnt));
1007 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1010 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1012 /// If last line finished on vertex the lines creation sequence has to be break
1013 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1015 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1016 // if there is an active widget, find the presented object in it
1017 if (!anActiveWidget)
1018 anActiveWidget = aPanel->preselectionWidget();
1020 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1022 if (aWidgetValidated)
1023 anObject = aWidgetValidated->findPresentedObject(theAIS);
1029 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1031 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1032 int aSelected = aObjects.size();
1033 SessionPtr aMgr = ModelAPI_Session::get();
1034 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1036 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1037 if (aSelected == 1) {
1038 bool hasResult = false;
1039 bool hasFeature = false;
1040 bool hasParameter = false;
1041 bool hasSubFeature = false;
1042 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
1044 ObjectPtr aObject = aObjects.first();
1046 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1047 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1048 bool isPart = aPart.get() ||
1049 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1051 DocumentPtr aPartDoc;
1053 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1055 if (aPart.get()) // this may be null is Part feature is disabled
1056 aPartDoc = aPart->partDoc();
1058 theMenu->addAction(aActivatePartAction);
1059 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1061 } else if (aObject->document() == aMgr->activeDocument()) {
1062 if (hasParameter || hasFeature) {
1063 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1064 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1065 if (aCurrentOp && aFeature.get()) {
1066 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1067 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1072 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1074 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
1077 bool aNotDeactivate = (aCurrentOp == 0);
1078 if (!aNotDeactivate) {
1079 aActivatePartAction->setEnabled(false);
1083 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1085 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1086 // Do not change activation of parts if an operation active
1087 static QStringList aAllowActivationList;
1088 if (aAllowActivationList.isEmpty())
1089 aAllowActivationList <<
1090 QString(PartSetPlugin_Part::ID().c_str()) <<
1091 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1092 QString(PartSetPlugin_Remove::ID().c_str());
1093 if (myWorkshop->currentOperation() &&
1094 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1096 XGUI_Workshop* aWorkshop = getWorkshop();
1097 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1098 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1099 QPalette aPalet = aLabel->palette();
1101 SessionPtr aMgr = ModelAPI_Session::get();
1102 DocumentPtr aActiveDoc = aMgr->activeDocument();
1103 if (aActivePartIndex.isValid())
1104 aTreeView->setExpanded(aActivePartIndex, false);
1105 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1106 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1107 if (aActivePartIndex.isValid())
1108 aTreeView->setExpanded(aActivePartIndex, true);
1110 aLabel->setPalette(aPalet);
1111 aWorkshop->updateCommandStatus();
1113 // Update displayed objects in order to update active color
1114 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1115 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1117 foreach(ObjectPtr aObj, aObjects) {
1118 //TODO: replace by redisplay event.
1119 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1120 aObj->isDisabled() || (!aObj->isDisplayed());
1122 aDisplayer->redisplay(aObj, false);
1124 aDisplayer->updateViewer();
1128 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1130 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1132 SessionPtr aMgr = ModelAPI_Session::get();
1133 if (!theIndex.isValid()) {
1134 aMgr->setActiveDocument(aMgr->moduleDocument());
1137 if (theIndex.column() != 0) // Use only first column
1140 XGUI_Workshop* aWorkshop = getWorkshop();
1141 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1142 // De not use non editable Indexes
1143 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1145 ObjectPtr aObj = aDataModel->object(theIndex);
1147 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1148 if (!aPart.get()) { // Probably this is Feature
1149 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1150 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1151 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1154 if (aPart.get()) { // if this is a part
1155 if (aPart->partDoc() == aMgr->activeDocument()) {
1156 myMenuMgr->activatePartSet();
1164 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1166 // z layer is created for all started operations in order to visualize operation AIS presentation
1168 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1169 if (aContext.IsNull())
1172 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1173 if (myVisualLayerId == 0) {
1174 if (myVisualLayerId == 0)
1175 aViewer->AddZLayer(myVisualLayerId);
1177 TColStd_SequenceOfInteger aZList;
1178 aViewer->GetAllZLayers(aZList);
1179 bool aFound = false;
1180 for (int i = 1; i <= aZList.Length(); i++) {
1181 if (aZList(i) == myVisualLayerId) {
1187 aViewer->AddZLayer(myVisualLayerId);
1189 // if there is an active operation with validated widget,
1190 // the filters of this widget should be activated in the created view
1191 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1193 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1194 if (anActiveWidget) {
1195 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1197 aWSelector->activateSelectionAndFilters(true);
1202 //******************************************************
1203 void PartSet_Module::widgetStateChanged(int thePreviousState)
1205 mySketchMgr->widgetStateChanged(thePreviousState);
1208 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1210 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1213 //******************************************************
1214 void PartSet_Module::beforeOperationStarted(ModuleBase_Operation* theOperation)
1218 //******************************************************
1219 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1221 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1222 mySketchMgr->stopSketch(theOperation);
1226 //******************************************************
1227 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1229 GeomShapePtr aGeomShape;
1231 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1232 if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1233 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1238 //******************************************************
1239 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1240 const GeomShapePtr& theGeomShape)
1242 AttributePtr anAttribute;
1243 GeomShapePtr aGeomShape = theGeomShape;
1244 if (!aGeomShape.get()) {
1245 // processing shape of result, e.g. sketch circle center is selected, this is a result
1246 // the geom shape is empty, the shape of result should be used
1247 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1248 if (aResult.get()) {
1249 aGeomShape = aResult->shape();
1253 if (aGeomShape.get()) {
1254 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1255 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1256 mySketchMgr->activeSketch());
1261 //******************************************************
1262 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1265 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1269 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1270 if (!aChoiceTitle.isEmpty()) {
1271 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1274 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1275 aPanel->setWindowTitle(aChoiceTitle);
1279 //******************************************************
1280 XGUI_Workshop* PartSet_Module::getWorkshop() const
1282 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1283 return aConnector->workshop();