]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetShapeSelector.cpp
Salome HOME
Issue #2120 - Crash when creating an arc passing through the arc connected to both...
[modules/shaper.git] / src / PartSet / PartSet_WidgetShapeSelector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetShapeSelector.cpp
4 // Created:     27 Nov 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "PartSet_WidgetShapeSelector.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_SketcherMgr.h"
10
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Validator.h>
14
15 #include <ModuleBase_Definitions.h>
16 #include <ModuleBase_ViewerPrs.h>
17
18 #include <Config_WidgetAPI.h>
19
20 #include <PartSet_ExternalObjectsMgr.h>
21 #include <SketchPlugin_Feature.h>
22
23 #include <XGUI_Workshop.h>
24
25 #include <XGUI_ModuleConnector.h>
26 #include <XGUI_Displayer.h>
27 #include <XGUI_SelectionMgr.h>
28 #include <XGUI_Selection.h>
29 #include <XGUI_Tools.h>
30
31 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
32                                                          ModuleBase_IWorkshop* theWorkshop,
33                                                          const Config_WidgetAPI* theData)
34 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
35 {
36   myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
37   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
38                                          theData->getProperty("can_create_external"), true);
39 }
40
41 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
42 {
43   delete myExternalObjectMgr;
44 }
45
46 //********************************************************************
47 bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
48 {
49   bool aHasSelectionFilter = ModuleBase_WidgetShapeSelector::activateSelectionAndFilters
50                                                                            (toActivate);
51   if (!myUseSketchPlane) {
52     XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
53     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(aWorkshop->module());
54     bool isUsePlaneFilterOnly = !toActivate;
55     aModule->sketchMgr()->activatePlaneFilter(isUsePlaneFilterOnly);
56   }
57   return aHasSelectionFilter;
58 }
59
60 //********************************************************************
61 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
62 {
63   bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
64   if (aValid) {
65     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
66     aValid = myExternalObjectMgr->isValidObject(anObject);
67   }
68   return aValid;
69 }
70
71 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
72                                                    ObjectPtr& theObject,
73                                                    GeomShapePtr& theShape)
74 {
75   ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
76
77   myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
78                                         myWorkshop, sketch(), myIsInValidate);
79   /*
80   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
81   std::shared_ptr<SketchPlugin_Feature> aSPFeature =
82           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
83   // there is no a sketch feature is selected, but the shape exists,
84   // try to create an exernal object
85   // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
86   if (aSPFeature.get() == NULL) {
87     ObjectPtr anExternalObject = ObjectPtr();
88     GeomShapePtr anExternalShape = GeomShapePtr();
89     if (myExternalObjectMgr->useExternal()) {
90       if (myExternalObjectMgr->canCreateExternal()) {
91         GeomShapePtr aShape = theShape;
92         if (!aShape.get()) {
93           ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
94           if (aResult.get())
95             aShape = aResult->shape();
96         }
97         if (aShape.get() != NULL && !aShape->isNull())
98           anExternalObject =
99             myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
100       }
101       else { /// use objects of found selection
102         anExternalObject = theObject;
103         anExternalShape = theShape;
104       }
105     }
106     /// the object is null if the selected feature is "external"(not sketch entity feature of the
107     /// current sketch) and it is not created by object manager
108     theObject = anExternalObject;
109     theShape = anExternalShape;
110   }*/
111 }
112
113 //********************************************************************
114 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
115                                                         const bool theValid)
116 {
117   ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
118   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
119 }
120