Salome HOME
updated copyright message
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Plugin.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
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
18 //
19
20 #include "ConstructionPlugin_Plugin.h"
21 #include "ConstructionPlugin_Point.h"
22 #include "ConstructionPlugin_Axis.h"
23 #include "ConstructionPlugin_Plane.h"
24 #include "ConstructionPlugin_Validators.h"
25
26 #include <Config_PropManager.h>
27
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Document.h>
30
31 #define SKETCH_WIDTH        "4"
32 /// face of the square-face displayed for selection of general plane
33 #define PLANE_SIZE          "200"
34
35 // the only created instance of this plugin
36 static ConstructionPlugin_Plugin* MY_CONSTRUCTION_INSTANCE = new ConstructionPlugin_Plugin();
37
38 ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
39 {
40   SessionPtr aMgr = ModelAPI_Session::get();
41   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
42   aFactory->registerValidator("ConstructionPlugin_ValidatorPointLines",
43                               new ConstructionPlugin_ValidatorPointLines());
44   aFactory->registerValidator("ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel",
45                               new ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel());
46   aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneThreePoints",
47                               new ConstructionPlugin_ValidatorPlaneThreePoints());
48   aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneLinePoint",
49                               new ConstructionPlugin_ValidatorPlaneLinePoint());
50   aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneTwoParallelPlanes",
51                               new ConstructionPlugin_ValidatorPlaneTwoParallelPlanes());
52   aFactory->registerValidator("ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes",
53                               new ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes());
54   aFactory->registerValidator("ConstructionPlugin_ValidatorPointThreeNonParallelPlanes",
55                               new ConstructionPlugin_ValidatorPointThreeNonParallelPlanes());
56   aFactory->registerValidator("ConstructionPlugin_ValidatorNotFeature",
57                               new ConstructionPlugin_ValidatorNotFeature());
58
59   Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::DblSpin,
60                                    PLANE_SIZE, "0", "1000");
61   Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness",
62     Config_Prop::IntSpin, SKETCH_WIDTH);
63   Config_PropManager::registerProp(SKETCH_TAB_NAME, "angular_tolerance", "Angular tolerance",
64     Config_Prop::DblSpin, "0.04");
65   Config_PropManager::registerProp(SKETCH_TAB_NAME, "spline_weight", "Default spline weight",
66     Config_Prop::DblSpin, "1.0");
67   Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane",
68     "Rotate to plane when selected", Config_Prop::Boolean, "false");
69   Config_PropManager::registerProp(SKETCH_TAB_NAME, "operation_cursor",
70     "Cursor for Sketch operation", Config_Prop::Cursor, "0");
71   Config_PropManager::registerProp(SKETCH_TAB_NAME, "create_by_dragging",
72     "Create sketch entities by dragging", Config_Prop::Boolean, "false");
73
74   // register this plugin
75   ModelAPI_Session::get()->registerPlugin(this);
76
77   // register construction properties
78   Config_PropManager::registerProp("Visualization", ConstructionPlugin_Plane::COLOR_NAME(),
79     "Construction plane color", Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
80
81   Config_PropManager::registerProp("Visualization", ConstructionPlugin_Point::COLOR_NAME(),
82     "Construction point color", Config_Prop::Color, ConstructionPlugin_Point::DEFAULT_COLOR());
83 }
84
85 FeaturePtr ConstructionPlugin_Plugin::createFeature(std::string theFeatureID)
86 {
87   if (theFeatureID == ConstructionPlugin_Point::ID()) {
88     return FeaturePtr(new ConstructionPlugin_Point);
89   }
90   else if (theFeatureID == ConstructionPlugin_Axis::ID()) {
91     return FeaturePtr(new ConstructionPlugin_Axis);
92   }
93   else if (theFeatureID == ConstructionPlugin_Plane::ID()) {
94     return FeaturePtr(new ConstructionPlugin_Plane);
95   }
96   // feature of such kind is not found
97   return FeaturePtr();
98 }