0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / IMeshTools / IMeshTools_Context.hxx
1 // Created on: 2016-04-07
2 // Copyright (c) 2016 OPEN CASCADE SAS
3 // Created by: Oleg AGASHIN
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _IMeshTools_Context_HeaderFile
17 #define _IMeshTools_Context_HeaderFile
18
19 #include <IMeshData_Shape.hxx>
20 #include <Standard_Type.hxx>
21 #include <IMeshTools_ModelBuilder.hxx>
22 #include <IMeshData_Model.hxx>
23 #include <IMeshTools_Parameters.hxx>
24 #include <IMeshTools_ModelAlgo.hxx>
25
26 //! Interface class representing context of BRepMesh algorithm.
27 //! Intended to cache discrete model and instances of tools for 
28 //! its processing.
29 class IMeshTools_Context : public IMeshData_Shape
30 {
31 public:
32
33   //! Constructor.
34   Standard_EXPORT IMeshTools_Context()
35   {
36   }
37
38   //! Destructor.
39   Standard_EXPORT virtual ~IMeshTools_Context()
40   {
41   }
42
43   //! Builds model using assined model builder.
44   //! @return True on success, False elsewhere.
45   Standard_EXPORT virtual Standard_Boolean BuildModel ()
46   {
47     if (myModelBuilder.IsNull())
48     {
49       return Standard_False;
50     }
51
52     myModel = myModelBuilder->Perform(GetShape(), myParameters);
53
54     return !myModel.IsNull();
55   }
56
57   //! Performs discretization of model edges using assigned edge discret algorithm.
58   //! @return True on success, False elsewhere.
59   Standard_EXPORT virtual Standard_Boolean DiscretizeEdges()
60   {
61     if (myModel.IsNull() || myEdgeDiscret.IsNull())
62     {
63       return Standard_False;
64     }
65
66     // Discretize edges of a model.
67     return myEdgeDiscret->Perform(myModel, myParameters);
68   }
69
70   //! Performs healing of discrete model built by DiscretizeEdges() method
71   //! using assigned healing algorithm.
72   //! @return True on success, False elsewhere.
73   Standard_EXPORT virtual Standard_Boolean HealModel()
74   {
75     if (myModel.IsNull())
76     {
77       return Standard_False;
78     }
79
80     return myModelHealer.IsNull() ?
81       Standard_True :
82       myModelHealer->Perform(myModel, myParameters);
83   }
84
85   //! Performs pre-processing of discrete model using assigned algorithm.
86   //! Performs auxiliary actions such as cleaning shape from old triangulation.
87   //! @return True on success, False elsewhere.
88   Standard_EXPORT virtual Standard_Boolean PreProcessModel()
89   {
90     if (myModel.IsNull())
91     {
92       return Standard_False;
93     }
94
95     return myPreProcessor.IsNull() ? 
96       Standard_True :
97       myPreProcessor->Perform(myModel, myParameters);
98   }
99
100   //! Performs meshing of faces of discrete model using assigned meshing algorithm.
101   //! @return True on success, False elsewhere.
102   Standard_EXPORT virtual Standard_Boolean DiscretizeFaces()
103   {
104     if (myModel.IsNull() || myFaceDiscret.IsNull())
105     {
106       return Standard_False;
107     }
108
109     // Discretize faces of a model.
110     return myFaceDiscret->Perform(myModel, myParameters);
111   }
112
113   //! Performs post-processing of discrete model using assigned algorithm.
114   //! @return True on success, False elsewhere.
115   Standard_EXPORT virtual Standard_Boolean PostProcessModel()
116   {
117     if (myModel.IsNull())
118     {
119       return Standard_False;
120     }
121
122     return myPostProcessor.IsNull() ?
123       Standard_True :
124       myPostProcessor->Perform(myModel, myParameters);
125   }
126
127   //! Cleans temporary context data.
128   Standard_EXPORT virtual void Clean()
129   {
130     if (myParameters.CleanModel)
131     {
132       myModel.Nullify();
133     }
134   }
135
136   //! Gets instance of a tool to be used to build discrete model.
137   inline const Handle (IMeshTools_ModelBuilder)& GetModelBuilder () const
138   {
139     return myModelBuilder;
140   }
141
142   //! Sets instance of a tool to be used to build discrete model.
143   inline void SetModelBuilder (const Handle (IMeshTools_ModelBuilder)& theBuilder)
144   {
145     myModelBuilder = theBuilder;
146   }
147
148   //! Gets instance of a tool to be used to discretize edges of a model.
149   inline const Handle (IMeshTools_ModelAlgo)& GetEdgeDiscret () const
150   {
151     return myEdgeDiscret;
152   }
153
154   //! Sets instance of a tool to be used to discretize edges of a model.
155   inline void SetEdgeDiscret (const Handle (IMeshTools_ModelAlgo)& theEdgeDiscret)
156   {
157     myEdgeDiscret = theEdgeDiscret;
158   }
159
160   //! Gets instance of a tool to be used to heal discrete model.
161   inline const Handle(IMeshTools_ModelAlgo)& GetModelHealer() const
162   {
163     return myModelHealer;
164   }
165
166   //! Sets instance of a tool to be used to heal discrete model.
167   inline void SetModelHealer(const Handle(IMeshTools_ModelAlgo)& theModelHealer)
168   {
169     myModelHealer = theModelHealer;
170   }
171
172   //! Gets instance of pre-processing algorithm.
173   inline const Handle(IMeshTools_ModelAlgo)& GetPreProcessor() const
174   {
175     return myPreProcessor;
176   }
177
178   //! Sets instance of pre-processing algorithm.
179   inline void SetPreProcessor(const Handle(IMeshTools_ModelAlgo)& thePreProcessor)
180   {
181     myPreProcessor = thePreProcessor;
182   }
183
184   //! Gets instance of meshing algorithm.
185   inline const Handle(IMeshTools_ModelAlgo)& GetFaceDiscret() const
186   {
187     return myFaceDiscret;
188   }
189
190   //! Sets instance of meshing algorithm.
191   inline void SetFaceDiscret(const Handle(IMeshTools_ModelAlgo)& theFaceDiscret)
192   {
193     myFaceDiscret = theFaceDiscret;
194   }
195
196   //! Gets instance of post-processing algorithm.
197   inline const Handle(IMeshTools_ModelAlgo)& GetPostProcessor() const
198   {
199     return myPostProcessor;
200   }
201
202   //! Sets instance of post-processing algorithm.
203   inline void SetPostProcessor(const Handle(IMeshTools_ModelAlgo)& thePostProcessor)
204   {
205     myPostProcessor = thePostProcessor;
206   }
207
208   //! Gets parameters to be used for meshing.
209   inline const IMeshTools_Parameters& GetParameters () const 
210   {
211     return myParameters;
212   }
213
214   //! Gets reference to parameters to be used for meshing.
215   inline IMeshTools_Parameters& ChangeParameters ()
216   {
217     return myParameters;
218   }
219
220   //! Returns discrete model of a shape.
221   inline const Handle (IMeshData_Model)& GetModel () const
222   {
223     return myModel;
224   }
225
226   DEFINE_STANDARD_RTTI_INLINE(IMeshTools_Context, IMeshData_Shape)
227
228 private:
229
230   Handle (IMeshTools_ModelBuilder) myModelBuilder;
231   Handle (IMeshData_Model)         myModel;
232   Handle (IMeshTools_ModelAlgo)    myEdgeDiscret;
233   Handle (IMeshTools_ModelAlgo)    myModelHealer;
234   Handle (IMeshTools_ModelAlgo)    myPreProcessor;
235   Handle (IMeshTools_ModelAlgo)    myFaceDiscret;
236   Handle (IMeshTools_ModelAlgo)    myPostProcessor;
237   IMeshTools_Parameters            myParameters;
238 };
239
240 #endif