Salome HOME
74136ce7a4ceab6317515dfbaffdd78bd44b7d7f
[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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "PartSet_WidgetShapeSelector.h"
22
23 #include "PartSet_CenterPrs.h"
24 #include "PartSet_Module.h"
25 #include "PartSet_SketcherMgr.h"
26
27 #include <ModelAPI_AttributeRefAttr.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Validator.h>
30
31 #include <ModuleBase_Definitions.h>
32 #include <ModuleBase_ViewerPrs.h>
33
34 #include <Config_WidgetAPI.h>
35
36 #include <PartSet_ExternalObjectsMgr.h>
37 #include <SketchPlugin_Feature.h>
38
39 #include <XGUI_Workshop.h>
40
41 #include <XGUI_ModuleConnector.h>
42 #include <XGUI_Displayer.h>
43 #include <XGUI_SelectionMgr.h>
44 #include <XGUI_Selection.h>
45 #include <XGUI_Tools.h>
46
47 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
48                                                          ModuleBase_IWorkshop* theWorkshop,
49                                                          const Config_WidgetAPI* theData)
50 : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
51 {
52   myUseSketchPlane = theData->getBooleanAttribute("use_sketch_plane", true);
53   myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
54                                          theData->getProperty("can_create_external"), true);
55 }
56
57 PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector()
58 {
59   delete myExternalObjectMgr;
60 }
61
62 //********************************************************************
63 void PartSet_WidgetShapeSelector::selectionFilters(int& theModuleSelectionFilters,
64                                                    SelectMgr_ListOfFilter& theSelectionFilters)
65 {
66   ModuleBase_WidgetShapeSelector::selectionFilters(theModuleSelectionFilters, theSelectionFilters);
67
68   if (!myUseSketchPlane) {
69     theModuleSelectionFilters = -1; // TODO!!!
70
71     //XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
72     //PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(aWorkshop->module());
73     //bool isUsePlaneFilterOnly = !toActivate;
74     //aModule->sketchMgr()->activatePlaneFilter(isUsePlaneFilterOnly);
75   }
76 }
77
78 //********************************************************************
79 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
80 {
81   bool aValid = false;
82   if (thePrs.get() && thePrs->interactive().get() &&
83       thePrs->interactive()->IsKind(STANDARD_TYPE(PartSet_CenterPrs)))
84     aValid = true; // we should not check acceptSubShape for such presentation
85   else
86     aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
87
88   if (aValid) {
89     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
90     aValid = myExternalObjectMgr->isValidObject(anObject);
91   }
92   return aValid;
93 }
94
95 void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
96                                                    ObjectPtr& theObject,
97                                                    GeomShapePtr& theShape)
98 {
99   ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
100
101   myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
102                                         myWorkshop, sketch(), myIsInValidate);
103 }
104
105 //********************************************************************
106 void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
107                                                         const bool theValid)
108 {
109   ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
110   myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
111 }
112