]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IBooleanOperations_i.cc
Salome HOME
PAL13456 : change default values for Vertex Maker style and size.
[modules/geom.git] / src / GEOM_I / GEOM_IBooleanOperations_i.cc
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include "GEOM_IBooleanOperations_i.hh"
24
25 #include "utilities.h"
26 #include "OpUtil.hxx"
27
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
30
31 #include <TColStd_HArray1OfInteger.hxx>
32
33 //=============================================================================
34 /*!
35  *   constructor:
36  */
37 //=============================================================================
38 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
39                                                       GEOM::GEOM_Gen_ptr theEngine,
40                                                       ::GEOMImpl_IBooleanOperations* theImpl)
41 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
42 {
43   MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
44 }
45
46 //=============================================================================
47 /*!
48  *  destructor
49  */
50 //=============================================================================
51 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
52 {
53   MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
54 }
55
56
57 //=============================================================================
58 /*!
59  *  MakeBoolean
60  */
61 //=============================================================================
62 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
63                                                  (GEOM::GEOM_Object_ptr theShape1,
64                                                   GEOM::GEOM_Object_ptr theShape2,
65                                                   CORBA::Long           theOp)
66 {
67   GEOM::GEOM_Object_var aGEOMObject;
68
69   //Set a not done flag
70   GetOperations()->SetNotDone();
71
72   if (theShape1 == NULL || theShape2 == NULL) return aGEOMObject._retn();
73
74   //Get the reference shapes
75   Handle(GEOM_Object) aSh1 = GetOperations()->GetEngine()->GetObject
76     (theShape1->GetStudyID(), theShape1->GetEntry());
77   Handle(GEOM_Object) aSh2 = GetOperations()->GetEngine()->GetObject
78     (theShape2->GetStudyID(), theShape2->GetEntry());
79
80   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
81
82   // Make Boolean
83   Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
84   if (!GetOperations()->IsDone() || anObject.IsNull())
85     return aGEOMObject._retn();
86
87   return GetObject(anObject);
88 }
89
90 //=============================================================================
91 /*!
92  *  MakePartition
93  */
94 //=============================================================================
95 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
96                                       (const GEOM::ListOfGO&   theShapes,
97                                        const GEOM::ListOfGO&   theTools,
98                                        const GEOM::ListOfGO&   theKeepIns,
99                                        const GEOM::ListOfGO&   theRemoveIns,
100                                        CORBA::Short            theLimit,
101                                        CORBA::Boolean          theRemoveWebs,
102                                        const GEOM::ListOfLong& theMaterials)
103 {
104   GEOM::GEOM_Object_var aGEOMObject;
105
106   //Set a not done flag
107   GetOperations()->SetNotDone();
108
109   int ind, aLen;
110   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
111   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
112   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
113   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
114   Handle(TColStd_HArray1OfInteger) aMaterials;
115
116   //Get the shapes
117   aLen = theShapes.length();
118   for (ind = 0; ind < aLen; ind++) {
119     if (theShapes[ind] == NULL) return aGEOMObject._retn();
120     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
121       (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
122     if (aSh.IsNull()) return aGEOMObject._retn();
123     aShapes->Append(aSh);
124   }
125
126   //Get the tools
127   aLen = theTools.length();
128   for (ind = 0; ind < aLen; ind++) {
129     if (theTools[ind] == NULL) return aGEOMObject._retn();
130     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
131       (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
132     if (aSh.IsNull()) return aGEOMObject._retn();
133     aTools->Append(aSh);
134   }
135
136   //Get the keep inside shapes
137   aLen = theKeepIns.length();
138   for (ind = 0; ind < aLen; ind++) {
139     if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
140     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
141       (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
142     if (aSh.IsNull()) return aGEOMObject._retn();
143     aKeepIns->Append(aSh);
144   }
145
146   //Get the remove inside shapes
147   aLen = theRemoveIns.length();
148   for (ind = 0; ind < aLen; ind++) {
149     if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
150     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
151       (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
152     if (aSh.IsNull()) return aGEOMObject._retn();
153     aRemIns->Append(aSh);
154   }
155
156   //Get the materials
157   aLen = theMaterials.length();
158   if ( aLen ) {
159     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
160     for (ind = 0; ind < aLen; ind++) {
161       aMaterials->SetValue(ind+1, theMaterials[ind]);
162     }
163   }
164
165   // Make Partition
166   Handle(GEOM_Object) anObject =
167     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
168                                    theLimit, theRemoveWebs, aMaterials,
169                                    /*PerformSelfIntersections*/Standard_True);
170   if (!GetOperations()->IsDone() || anObject.IsNull())
171     return aGEOMObject._retn();
172
173   return GetObject(anObject);
174 }
175
176 //=============================================================================
177 /*!
178  *  MakePartitionNonSelfIntersectedShape
179  */
180 //=============================================================================
181 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
182                                       (const GEOM::ListOfGO&   theShapes,
183                                        const GEOM::ListOfGO&   theTools,
184                                        const GEOM::ListOfGO&   theKeepIns,
185                                        const GEOM::ListOfGO&   theRemoveIns,
186                                        CORBA::Short            theLimit,
187                                        CORBA::Boolean          theRemoveWebs,
188                                        const GEOM::ListOfLong& theMaterials)
189 {
190   GEOM::GEOM_Object_var aGEOMObject;
191
192   //Set a not done flag
193   GetOperations()->SetNotDone();
194
195   int ind, aLen;
196   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
197   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
198   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
199   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
200   Handle(TColStd_HArray1OfInteger) aMaterials;
201
202   //Get the shapes
203   aLen = theShapes.length();
204   for (ind = 0; ind < aLen; ind++) {
205     if (theShapes[ind] == NULL) return aGEOMObject._retn();
206     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
207       (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
208     if (aSh.IsNull()) return aGEOMObject._retn();
209     aShapes->Append(aSh);
210   }
211
212   //Get the tools
213   aLen = theTools.length();
214   for (ind = 0; ind < aLen; ind++) {
215     if (theTools[ind] == NULL) return aGEOMObject._retn();
216     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
217       (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
218     if (aSh.IsNull()) return aGEOMObject._retn();
219     aTools->Append(aSh);
220   }
221
222   //Get the keep inside shapes
223   aLen = theKeepIns.length();
224   for (ind = 0; ind < aLen; ind++) {
225     if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
226     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
227       (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
228     if (aSh.IsNull()) return aGEOMObject._retn();
229     aKeepIns->Append(aSh);
230   }
231
232   //Get the remove inside shapes
233   aLen = theRemoveIns.length();
234   for (ind = 0; ind < aLen; ind++) {
235     if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
236     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
237       (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
238     if (aSh.IsNull()) return aGEOMObject._retn();
239     aRemIns->Append(aSh);
240   }
241
242   //Get the materials
243   aLen = theMaterials.length();
244   if ( aLen ) {
245     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
246     for (ind = 0; ind < aLen; ind++) {
247       aMaterials->SetValue(ind+1, theMaterials[ind]);
248     }
249   }
250
251   // Make Partition
252   Handle(GEOM_Object) anObject =
253     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
254                                    theLimit, theRemoveWebs, aMaterials,
255                                    /*PerformSelfIntersections*/Standard_False);
256   if (!GetOperations()->IsDone() || anObject.IsNull())
257     return aGEOMObject._retn();
258
259   return GetObject(anObject);
260 }
261
262 //=============================================================================
263 /*!
264  *  MakeHalfPartition
265  */
266 //=============================================================================
267 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
268                                                  (GEOM::GEOM_Object_ptr theShape,
269                                                   GEOM::GEOM_Object_ptr thePlane)
270 {
271   GEOM::GEOM_Object_var aGEOMObject;
272
273   //Set a not done flag
274   GetOperations()->SetNotDone();
275
276   if (theShape == NULL || thePlane == NULL) return aGEOMObject._retn();
277
278   //Get the reference shapes
279   Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
280     (theShape->GetStudyID(), theShape->GetEntry());
281   Handle(GEOM_Object) aPl = GetOperations()->GetEngine()->GetObject
282     (thePlane->GetStudyID(), thePlane->GetEntry());
283
284   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
285
286   // Make Half Partition
287   Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
288   if (!GetOperations()->IsDone() || anObject.IsNull())
289     return aGEOMObject._retn();
290
291   return GetObject(anObject);
292 }