Salome HOME
Copyrights update
[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/
19 //
20 #include <Standard_Stream.hxx>
21
22 #include "GEOM_IBooleanOperations_i.hh"
23
24 #include "utilities.h"
25 #include "OpUtil.hxx"
26
27 #include "GEOM_Engine.hxx"
28 #include "GEOM_Object.hxx"
29
30 #include <TColStd_HArray1OfInteger.hxx>
31
32 //=============================================================================
33 /*!
34  *   constructor:
35  */
36 //=============================================================================
37 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
38                                                       GEOM::GEOM_Gen_ptr theEngine,
39                                                       ::GEOMImpl_IBooleanOperations* theImpl)
40 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
41 {
42   MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
43 }
44
45 //=============================================================================
46 /*!
47  *  destructor
48  */
49 //=============================================================================
50 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
51 {
52   MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
53 }
54
55
56 //=============================================================================
57 /*!
58  *  MakeBoolean
59  */
60 //============================================================================= 
61 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
62                                                  (GEOM::GEOM_Object_ptr theShape1,
63                                                   GEOM::GEOM_Object_ptr theShape2,
64                                                   CORBA::Long           theOp)
65 {
66   GEOM::GEOM_Object_var aGEOMObject;
67
68   //Set a not done flag
69   GetOperations()->SetNotDone();
70
71   if (theShape1 == NULL || theShape2 == NULL) return aGEOMObject._retn();
72
73   //Get the reference shapes
74   Handle(GEOM_Object) aSh1 = GetOperations()->GetEngine()->GetObject
75     (theShape1->GetStudyID(), theShape1->GetEntry());
76   Handle(GEOM_Object) aSh2 = GetOperations()->GetEngine()->GetObject
77     (theShape2->GetStudyID(), theShape2->GetEntry());
78
79   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
80
81   // Make Boolean
82   Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
83   if (!GetOperations()->IsDone() || anObject.IsNull())
84     return aGEOMObject._retn();
85
86   return GetObject(anObject);
87 }
88
89 //=============================================================================
90 /*!
91  *  MakePartition
92  */
93 //============================================================================= 
94 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
95                                       (const GEOM::ListOfGO&   theShapes,
96                                        const GEOM::ListOfGO&   theTools,
97                                        const GEOM::ListOfGO&   theKeepIns,
98                                        const GEOM::ListOfGO&   theRemoveIns,
99                                        const CORBA::Short      theLimit,
100                                        const CORBA::Boolean    theRemoveWebs,
101                                        const GEOM::ListOfLong& theMaterials)
102 {
103   GEOM::GEOM_Object_var aGEOMObject;
104
105   //Set a not done flag
106   GetOperations()->SetNotDone();
107
108   int ind, aLen;
109   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
110   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
111   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
112   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
113   Handle(TColStd_HArray1OfInteger) aMaterials;
114
115   //Get the shapes
116   aLen = theShapes.length();
117   for (ind = 0; ind < aLen; ind++) {
118     if (theShapes[ind] == NULL) return aGEOMObject._retn();
119     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
120       (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
121     if (aSh.IsNull()) return aGEOMObject._retn();
122     aShapes->Append(aSh);
123   }
124
125   //Get the tools
126   aLen = theTools.length();
127   for (ind = 0; ind < aLen; ind++) {
128     if (theTools[ind] == NULL) return aGEOMObject._retn();
129     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
130       (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
131     if (aSh.IsNull()) return aGEOMObject._retn();
132     aTools->Append(aSh);
133   }
134
135   //Get the keep inside shapes
136   aLen = theKeepIns.length();
137   for (ind = 0; ind < aLen; ind++) {
138     if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
139     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
140       (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
141     if (aSh.IsNull()) return aGEOMObject._retn();
142     aKeepIns->Append(aSh);
143   }
144
145   //Get the remove inside shapes
146   aLen = theRemoveIns.length();
147   for (ind = 0; ind < aLen; ind++) {
148     if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
149     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
150       (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
151     if (aSh.IsNull()) return aGEOMObject._retn();
152     aRemIns->Append(aSh);
153   }
154
155   //Get the materials
156   aLen = theMaterials.length();
157   aMaterials = new TColStd_HArray1OfInteger (1, aLen);
158   for (ind = 0; ind < aLen; ind++) {
159     aMaterials->SetValue(ind+1, theMaterials[ind]);
160   }
161
162   // Make Partition
163   Handle(GEOM_Object) anObject =
164     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
165                                    theLimit, theRemoveWebs, aMaterials);
166   if (!GetOperations()->IsDone() || anObject.IsNull())
167     return aGEOMObject._retn();
168
169   return GetObject(anObject);
170 }
171
172 //=============================================================================
173 /*!
174  *  MakeHalfPartition
175  */
176 //============================================================================= 
177 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
178                                                  (GEOM::GEOM_Object_ptr theShape,
179                                                   GEOM::GEOM_Object_ptr thePlane)
180 {
181   GEOM::GEOM_Object_var aGEOMObject;
182
183   //Set a not done flag
184   GetOperations()->SetNotDone();
185
186   if (theShape == NULL || thePlane == NULL) return aGEOMObject._retn();
187
188   //Get the reference shapes
189   Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
190     (theShape->GetStudyID(), theShape->GetEntry());
191   Handle(GEOM_Object) aPl = GetOperations()->GetEngine()->GetObject
192     (thePlane->GetStudyID(), thePlane->GetEntry());
193
194   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
195
196   // Make Half Partition
197   Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
198   if (!GetOperations()->IsDone() || anObject.IsNull())
199     return aGEOMObject._retn();
200
201   return GetObject(anObject);
202 }