Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / Model / Model_ResultPart.h
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 #ifndef Model_ResultPart_H_
22 #define Model_ResultPart_H_
23
24 #include "Model.h"
25 #include <ModelAPI_ResultPart.h>
26 #include <TopoDS_Shape.hxx>
27 #include <gp_Trsf.hxx>
28
29 /**\class Model_ResultPart
30  * \ingroup DataModel
31  * \brief The Part document, result of a creation of new part feature.
32  *
33  * This result leaves without feature: no parametricity for this element,
34  * only add/remove, undo/redo.
35  */
36 class Model_ResultPart : public ModelAPI_ResultPart
37 {
38   /// shape of this part created from bodies (updated only of Part deactivation)
39   TopoDS_Shape myShape;
40   /// if it is just copy of original shape, keep just transformation
41   std::shared_ptr<gp_Trsf> myTrsf;
42  public:
43
44   /// the reference to the base result document, may be null if this is the root,
45   /// others make sequence of references
46   inline static const std::string& BASE_REF_ID()
47   {
48     static const std::string MY_BASE_REF("BaseReference");
49     return MY_BASE_REF;
50   }
51   /// Request for initialization of data model of the result: adding all attributes
52   virtual void initAttributes();
53   /// Returns the part-document of this result
54   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> partDoc();
55
56   /// Returns the original part result: for transfomration features results this is
57   /// the original Part feature result
58   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultPart> original();
59
60   /// Sets this document as current and if it is not loaded yet, loads it
61   MODEL_EXPORT virtual void activate();
62
63   /// disable all feature of the part on disable of the part result
64   MODEL_EXPORT virtual bool setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
65     const bool theFlag);
66
67   /// Result shape of part document is compound of bodies inside of this part
68   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
69
70   /// Returns the name of the shape inside of the part
71   /// \param theShape selected shape in this document
72   /// \param theIndex is returned as one-based index if selection was required, "0" otherwise
73   /// \returns empty name is selection is not correct
74   MODEL_EXPORT virtual std::string nameInPart(const std::shared_ptr<GeomAPI_Shape>& theShape,
75     int& theIndex);
76
77   /// Updates the selection inside of the part by the selection index
78   MODEL_EXPORT virtual bool updateInPart(const int theIndex);
79   /// Returns the shape by the name in the part
80   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(
81     const std::string& theName, const std::string& theType, int& theIndex);
82   /// Updates the shape-result of the part (called on Part feature execution)
83   MODEL_EXPORT virtual void updateShape();
84   /// Applies the additional transformation of the part
85   MODEL_EXPORT virtual void setTrsf(std::shared_ptr<ModelAPI_Result> theThis,
86     const std::shared_ptr<GeomAPI_Trsf>& theTransformation);
87
88   /// Returns the parameters of color definition in the resources config manager
89   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
90                                             std::string& theDefault);
91
92   /// Returns the shape selected in the selection index
93   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> selectionValue(const int theIndex);
94
95 protected:
96   /// makes a result on a temporary feature (an action)
97   Model_ResultPart();
98
99   /// returns sum of transformations of the whole sequence of transformation-parts
100   gp_Trsf sumTrsf();
101
102   /// Returns true if document is activated (loaded into the memory)
103   virtual bool isActivated();
104
105   friend class Model_Objects;
106 };
107
108 #endif