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