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