]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetShapeSelector.cpp
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / PartSet / PartSet_WidgetShapeSelector.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #include "PartSet_WidgetShapeSelector.h"
21 #include "PartSet_Module.h"
22 #include "PartSet_SketcherMgr.h"
23
24 #include <ModelAPI_AttributeRefAttr.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Validator.h>
27
28 #include <ModuleBase_Definitions.h>
29 #include <ModuleBase_ViewerPrs.h>
30
31 #include <Config_WidgetAPI.h>
32
33 #include <PartSet_ExternalObjectsMgr.h>
34 #include <SketchPlugin_Feature.h>
35
36 #include <XGUI_Workshop.h>
37
38 #include <XGUI_ModuleConnector.h>
39 #include <XGUI_Displayer.h>
40 #include <XGUI_SelectionMgr.h>
41 #include <XGUI_Selection.h>
42 #include <XGUI_Tools.h>
43
44 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
45                                                          ModuleBase_IWorkshop* theWorkshop,
46                                                          const Config_WidgetAPI* theData)
47 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
48 {
49   myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
50   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
51                                          theData->getProperty("can_create_external"), true);
52 }
53
54 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
55 {
56   delete myExternalObjectMgr;
57 }
58
59 //********************************************************************
60 bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
61 {
62   bool aHasSelectionFilter = ModuleBase_WidgetShapeSelector::activateSelectionAndFilters
63                                                                            (toActivate);
64   if (!myUseSketchPlane) {
65     XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
66     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(aWorkshop->module());
67     bool isUsePlaneFilterOnly = !toActivate;
68     aModule->sketchMgr()->activatePlaneFilter(isUsePlaneFilterOnly);
69   }
70   return aHasSelectionFilter;
71 }
72
73 //********************************************************************
74 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
75 {
76   bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
77   if (aValid) {
78     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
79     aValid = myExternalObjectMgr->isValidObject(anObject);
80   }
81   return aValid;
82 }
83
84 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
85                                                    ObjectPtr& theObject,
86                                                    GeomShapePtr& theShape)
87 {
88   ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
89
90   myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
91                                         myWorkshop, sketch(), myIsInValidate);
92   /*
93   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
94   std::shared_ptr<SketchPlugin_Feature> aSPFeature =
95           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
96   // there is no a sketch feature is selected, but the shape exists,
97   // try to create an exernal object
98   // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
99   if (aSPFeature.get() == NULL) {
100     ObjectPtr anExternalObject = ObjectPtr();
101     GeomShapePtr anExternalShape = GeomShapePtr();
102     if (myExternalObjectMgr->useExternal()) {
103       if (myExternalObjectMgr->canCreateExternal()) {
104         GeomShapePtr aShape = theShape;
105         if (!aShape.get()) {
106           ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
107           if (aResult.get())
108             aShape = aResult->shape();
109         }
110         if (aShape.get() != NULL && !aShape->isNull())
111           anExternalObject =
112             myExternalObjectMgr->externalObject(theObject, aShape, sketch(), myIsInValidate);
113       }
114       else { /// use objects of found selection
115         anExternalObject = theObject;
116         anExternalShape = theShape;
117       }
118     }
119     /// the object is null if the selected feature is "external"(not sketch entity feature of the
120     /// current sketch) and it is not created by object manager
121     theObject = anExternalObject;
122     theShape = anExternalShape;
123   }*/
124 }
125
126 //********************************************************************
127 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
128                                                         const bool theValid)
129 {
130   ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
131   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
132 }
133