Salome HOME
eba4c129cc5b07bf13843a36ca706543c2d0f83e
[modules/shaper.git] / src / Model / Model_ResultConstruction.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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef Model_ResultConstruction_H_
21 #define Model_ResultConstruction_H_
22
23 #include "Model.h"
24 #include <ModelAPI_ResultConstruction.h>
25 #include <vector>
26
27 class ModelAPI_Document;
28 class TDF_Label;
29
30 /**\class Model_ResultConstruction
31  * \ingroup DataModel
32  * \brief The construction element result of a feature.
33  *
34  * Provides a shape that may be displayed in the viewer.
35  * Intermediate, light result that in many cases produces a result on the fly.
36  */
37 class Model_ResultConstruction : public ModelAPI_ResultConstruction
38 {
39   std::shared_ptr<ModelAPI_Feature> myOwner;  ///< owner of this result
40   std::shared_ptr<GeomAPI_Shape> myShape;  ///< shape of this result created "on the fly"
41   bool myFacesUpToDate; ///< is true if faces in myuFaces are computed and up to date
42   /// stores the up to date faces if they exist
43   std::vector<std::shared_ptr<GeomAPI_Face> > myFaces;
44   bool myIsInHistory;
45   bool myIsInfinite;
46  public:
47   /// Retuns the parameters of color definition in the resources config manager
48   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
49                                             std::string& theDefault);
50
51   /// By default object is displayed in the object browser.
52   MODEL_EXPORT virtual bool isInHistory()
53   {
54     return myIsInHistory;
55   }
56
57   /// Sets the result
58   MODEL_EXPORT virtual void setShape(std::shared_ptr<GeomAPI_Shape> theShape);
59   /// Returns the shape-result produced by this feature
60   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
61
62   /// Sets the flag that it must be displayed in history (default is true)
63   MODEL_EXPORT virtual void setIsInHistory(const bool myIsInHistory);
64
65   /// if the construction result may be used as faces, this method returns not zero number of faces
66   MODEL_EXPORT virtual int facesNum();
67   /// if the construction result may be used as faces, this method returns face by zero based index
68   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Face> face(const int theIndex);
69
70   /// By default object is not infinite.
71   MODEL_EXPORT virtual bool isInfinite();
72   /// Sets the flag that it is infinite
73   MODEL_EXPORT virtual void setInfinite(const bool theInfinite);
74   /// The construction element is never concealed
75   MODEL_EXPORT virtual void setIsConcealed(const bool theValue);
76
77   // methods related to selection of sub-shapes in construction, used by SelectionAttribute
78
79   /// Selects theSubShape in the construction. Returns an index of the selected sub-shape.
80   /// Puts the selected shape with a needed BRepNaming sub-structure to the data tree of result.
81   /// If theSubShape is null, it selects the whole construction and returns zero index.
82   /// If theIndex is not -1, it re-selects over the existing data (used for update selection).
83   /// If theExtDoc is document where this selection is needed, if it differs from this,
84   /// naming structures will be located there.
85   int select(const std::shared_ptr<GeomAPI_Shape>& theSubShape,
86     const std::shared_ptr<ModelAPI_Document> theExtDoc, const int theIndex = -1);
87
88   /// Returns already selected shape by the given index. Zero index means the whole construction,
89   /// so, the returned shape in this case is null.
90   /// If theExtDoc is document where this selection is needed, if it differs from this,
91   /// naming structures will be located there.
92   std::shared_ptr<GeomAPI_Shape> shape(const int theIndex,
93     const std::shared_ptr<ModelAPI_Document> theExtDoc);
94
95   /// Updates the existing selection by the index.
96   /// Returns false if update is failed. Returns theModified true if the selection was updated.
97   /// If theExtDoc is document where this selection is needed, if it differs from this,
98   /// naming structures will be updated there.
99   bool update(const int theIndex, const std::shared_ptr<ModelAPI_Document> theExtDoc,
100     bool& theModified);
101
102  protected:
103   /// Makes a body on the given feature
104   Model_ResultConstruction();
105
106   /// Searchies for the working label selection/update will start from
107   /// Returns true if this is label of the external document.
108   /// theExtDoc is document where this selection is required
109   TDF_Label startLabel(const std::shared_ptr<ModelAPI_Document> theExtDoc, bool& theExternal);
110
111   friend class Model_Objects;
112 };
113
114 #endif