Salome HOME
04864cfb6543d5bb365d4daea83eaa5d86e7db4f
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Plugin.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 "ConstructionPlugin_Plugin.h"
22 #include "ConstructionPlugin_Point.h"
23 #include "ConstructionPlugin_Axis.h"
24 #include "ConstructionPlugin_Plane.h"
25 #include "ConstructionPlugin_Validators.h"
26
27 #include <Config_PropManager.h>
28
29 #include <ModelAPI_Session.h>
30 #include <ModelAPI_Document.h>
31
32 #define SKETCH_WIDTH        "4"
33 /// face of the square-face displayed for selection of general plane
34 #define PLANE_SIZE          "200"
35
36 // the only created instance of this plugin
37 static ConstructionPlugin_Plugin* MY_CONSTRUCTION_INSTANCE = new ConstructionPlugin_Plugin();
38
39 ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
40 {
41   SessionPtr aMgr = ModelAPI_Session::get();
42   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
43   aFactory->registerValidator("ConstructionPlugin_ValidatorPointLines",
44                               new ConstructionPlugin_ValidatorPointLines());
45   aFactory->registerValidator("ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel",
46                               new ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel());
47   aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneThreePoints",
48                               new ConstructionPlugin_ValidatorPlaneThreePoints());
49   aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneLinePoint",
50                               new ConstructionPlugin_ValidatorPlaneLinePoint());
51   aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneTwoParallelPlanes",
52                               new ConstructionPlugin_ValidatorPlaneTwoParallelPlanes());
53   aFactory->registerValidator("ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes",
54                               new ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes());
55
56   Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::Double,
57                                    PLANE_SIZE);
58   Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness",
59                                    Config_Prop::Integer, SKETCH_WIDTH);
60   Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane",
61     "Rotate to plane when selected", Config_Prop::Boolean, "false");
62
63   // register this plugin
64   ModelAPI_Session::get()->registerPlugin(this);
65
66   // register construction properties
67   Config_PropManager::registerProp("Visualization", "construction_plane_color",
68                                    "Construction plane color",
69                                    Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
70 }
71
72 FeaturePtr ConstructionPlugin_Plugin::createFeature(std::string theFeatureID)
73 {
74   if (theFeatureID == ConstructionPlugin_Point::ID()) {
75     return FeaturePtr(new ConstructionPlugin_Point);
76   }
77   else if (theFeatureID == ConstructionPlugin_Axis::ID()) {
78     return FeaturePtr(new ConstructionPlugin_Axis);
79   }
80   else if (theFeatureID == ConstructionPlugin_Plane::ID()) {
81     return FeaturePtr(new ConstructionPlugin_Plane);
82   }
83   // feature of such kind is not found
84   return FeaturePtr();
85 }