Salome HOME
Implementation of gluing faces by given list (for PAL13191).
[modules/geom.git] / src / GEOM_I / GEOM_IBasicOperations_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 #include <Standard_Stream.hxx>
21
22 #include "GEOM_IBasicOperations_i.hh"
23
24 #include "utilities.h"
25 #include "OpUtil.hxx"
26 #include "Utils_ExceptHandlers.hxx"
27
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
30
31 //=============================================================================
32 /*!
33  *   constructor:
34  */
35 //=============================================================================
36 GEOM_IBasicOperations_i::GEOM_IBasicOperations_i (PortableServer::POA_ptr thePOA,
37                                                   GEOM::GEOM_Gen_ptr theEngine,
38                                                   ::GEOMImpl_IBasicOperations* theImpl)
39      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
40 {
41   MESSAGE("GEOM_IBasicOperations_i::GEOM_IBasicOperations_i");
42 }
43
44 //=============================================================================
45 /*!
46  *  destructor
47  */
48 //=============================================================================
49 GEOM_IBasicOperations_i::~GEOM_IBasicOperations_i()
50 {
51   MESSAGE("GEOM_IBasicOperations_i::~GEOM_IBasicOperations_i");
52 }
53
54
55 //=============================================================================
56 /*!
57  *  MakePointXYZ
58  */
59 //=============================================================================
60 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointXYZ
61   (CORBA::Double theX, CORBA::Double theY, CORBA::Double theZ)
62 {
63   GEOM::GEOM_Object_var aGEOMObject;
64
65   //Set a not done flag
66   GetOperations()->SetNotDone();
67
68    //Create the point
69
70   Handle(GEOM_Object) anObject = GetOperations()->MakePointXYZ(theX, theY, theZ);
71   if (!GetOperations()->IsDone() || anObject.IsNull())
72     return aGEOMObject._retn();
73
74   return GetObject(anObject);
75 }
76
77 //=============================================================================
78 /*!
79  *  MakePointWithReference
80  */
81 //=============================================================================
82 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointWithReference
83   (GEOM::GEOM_Object_ptr theReference, CORBA::Double theX, CORBA::Double theY, CORBA::Double theZ)
84 {
85   GEOM::GEOM_Object_var aGEOMObject;
86
87   //Set a not done flag
88   GetOperations()->SetNotDone();
89
90   if(theReference == NULL) return aGEOMObject._retn();
91
92   //Get the reference point
93
94   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
95     (theReference->GetStudyID(), theReference->GetEntry());
96   if (aRefernce.IsNull()) return aGEOMObject._retn();
97
98   //Create the point
99
100   Handle(GEOM_Object) anObject =
101     GetOperations()->MakePointWithReference(aRefernce, theX, theY, theZ);
102   if (!GetOperations()->IsDone() || anObject.IsNull())
103     return aGEOMObject._retn();
104
105   return GetObject(anObject);
106 }
107
108 //=============================================================================
109 /*!
110  *  MakePointOnCurve
111  */
112 //=============================================================================
113 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnCurve
114                   (GEOM::GEOM_Object_ptr theCurve,  CORBA::Double theParameter)
115 {
116   GEOM::GEOM_Object_var aGEOMObject;
117
118   //Set a not done flag
119   GetOperations()->SetNotDone();
120
121   if (theCurve == NULL) return aGEOMObject._retn();
122
123   //Get the reference curve
124
125   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
126     (theCurve->GetStudyID(), theCurve->GetEntry());
127   if (aRefernce.IsNull()) return aGEOMObject._retn();
128
129   //Create the point
130
131   Handle(GEOM_Object) anObject =
132     GetOperations()->MakePointOnCurve(aRefernce, theParameter);
133   if (!GetOperations()->IsDone() || anObject.IsNull())
134     return aGEOMObject._retn();
135
136   return GetObject(anObject);
137 }
138
139 //=============================================================================
140 /*!
141  *  MakeTangentOnCurve
142  */
143 //=============================================================================
144 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeTangentOnCurve
145                   (GEOM::GEOM_Object_ptr theCurve,  CORBA::Double theParameter)
146 {
147   GEOM::GEOM_Object_var aGEOMObject;
148
149   //Set a not done flag
150   GetOperations()->SetNotDone();
151
152   if (theCurve == NULL) return aGEOMObject._retn();
153
154   //Get the reference curve
155
156   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
157     (theCurve->GetStudyID(), theCurve->GetEntry());
158   if (aRefernce.IsNull()) return aGEOMObject._retn();
159
160   //Create the point
161
162   Handle(GEOM_Object) anObject =
163     GetOperations()->MakeTangentOnCurve(aRefernce, theParameter);
164   if (!GetOperations()->IsDone() || anObject.IsNull())
165     return aGEOMObject._retn();
166
167   return GetObject(anObject);
168 }
169
170
171 //=============================================================================
172 /*!
173  *  MakeVectorDXDYDZ
174  */
175 //=============================================================================
176 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeVectorDXDYDZ
177   (CORBA::Double theDX, CORBA::Double theDY, CORBA::Double theDZ)
178 {
179   GEOM::GEOM_Object_var aGEOMObject;
180
181   //Set a not done flag
182   GetOperations()->SetNotDone();
183
184   //Create the Vector
185
186   Handle(GEOM_Object) anObject = GetOperations()->MakeVectorDXDYDZ(theDX, theDY, theDZ);
187   if (!GetOperations()->IsDone() || anObject.IsNull())
188     return aGEOMObject._retn();
189
190   return GetObject(anObject);
191 }
192
193 //=============================================================================
194 /*!
195  *  MakeVectorTwoPnt
196  */
197 //=============================================================================
198 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeVectorTwoPnt
199                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
200 {
201   GEOM::GEOM_Object_var aGEOMObject;
202
203   //Set a not done flag
204   GetOperations()->SetNotDone();
205
206   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
207
208   //Get the reference points
209
210   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
211     (thePnt1->GetStudyID(), thePnt1->GetEntry());
212   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
213     (thePnt2->GetStudyID(), thePnt2->GetEntry());
214   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
215
216   //Create the vector
217
218   Handle(GEOM_Object) anObject =
219     GetOperations()->MakeVectorTwoPnt(aRef1, aRef2);
220   if (!GetOperations()->IsDone() || anObject.IsNull())
221     return aGEOMObject._retn();
222
223   return GetObject(anObject);
224 }
225
226
227 //=============================================================================
228 /*!
229  *  MakeLine
230  */
231 //=============================================================================
232 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeLine
233                    (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theDir)
234 {
235   GEOM::GEOM_Object_var aGEOMObject;
236
237   //Set a not done flag
238   GetOperations()->SetNotDone();
239
240   if (thePnt == NULL || theDir == NULL) return aGEOMObject._retn();
241
242   //Get the reference objects
243
244   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
245     (thePnt->GetStudyID(), thePnt->GetEntry());
246   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
247     (theDir->GetStudyID(), theDir->GetEntry());
248   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
249
250   //Create the Line
251
252   Handle(GEOM_Object) anObject =
253     GetOperations()->MakeLine(aRef1, aRef2);
254   if (!GetOperations()->IsDone() || anObject.IsNull())
255     return aGEOMObject._retn();
256
257   return GetObject(anObject);
258 }
259
260 //=============================================================================
261 /*!
262  *  MakeLineTwoPnt
263  */
264 //=============================================================================
265 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeLineTwoPnt
266                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
267 {
268   GEOM::GEOM_Object_var aGEOMObject;
269
270   //Set a not done flag
271   GetOperations()->SetNotDone();
272
273   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
274
275   //Get the reference points
276
277   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
278     (thePnt1->GetStudyID(), thePnt1->GetEntry());
279   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
280     (thePnt2->GetStudyID(), thePnt2->GetEntry());
281   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
282
283   //Create the Line
284
285   Handle(GEOM_Object) anObject =
286     GetOperations()->MakeLineTwoPnt(aRef1, aRef2);
287   if (!GetOperations()->IsDone() || anObject.IsNull())
288     return aGEOMObject._retn();
289
290   return GetObject(anObject);
291 }
292
293
294 //=============================================================================
295 /*!
296  *  MakePlanePntVec
297  */
298 //=============================================================================
299 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlanePntVec
300                  (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
301                   CORBA::Double theTrimSize)
302 {
303   GEOM::GEOM_Object_var aGEOMObject;
304
305   //Set a not done flag
306   GetOperations()->SetNotDone();
307
308   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
309
310   //Get the references
311
312   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
313     (thePnt->GetStudyID(), thePnt->GetEntry());
314   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
315     (theVec->GetStudyID(), theVec->GetEntry());
316   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
317
318   //Create the plane
319
320   Handle(GEOM_Object) anObject =
321     GetOperations()->MakePlanePntVec(aRef1, aRef2, theTrimSize);
322   if (!GetOperations()->IsDone() || anObject.IsNull())
323     return aGEOMObject._retn();
324
325   return GetObject(anObject);
326 }
327
328 //=============================================================================
329 /*!
330  *  MakePlaneThreePnt
331  */
332 //=============================================================================
333 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlaneThreePnt
334                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
335                   GEOM::GEOM_Object_ptr thePnt3, CORBA::Double theTrimSize)
336 {
337   GEOM::GEOM_Object_var aGEOMObject;
338
339   //Set a not done flag
340   GetOperations()->SetNotDone();
341
342   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL)
343     return aGEOMObject._retn();
344
345   //Get the reference points
346
347   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
348     (thePnt1->GetStudyID(), thePnt1->GetEntry());
349   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
350     (thePnt2->GetStudyID(), thePnt2->GetEntry());
351   Handle(GEOM_Object) aRef3 = GetOperations()->GetEngine()->GetObject
352     (thePnt3->GetStudyID(), thePnt3->GetEntry());
353   if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull())
354     return aGEOMObject._retn();
355
356   //Create the plane
357
358   Handle(GEOM_Object) anObject =
359     GetOperations()->MakePlaneThreePnt(aRef1, aRef2, aRef3, theTrimSize);
360   if (!GetOperations()->IsDone() || anObject.IsNull())
361     return aGEOMObject._retn();
362
363   return GetObject(anObject);
364 }
365
366 //=============================================================================
367 /*!
368  *  MakePlaneFace
369  */
370 //=============================================================================
371 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlaneFace
372                      (GEOM::GEOM_Object_ptr theFace, CORBA::Double theTrimSize)
373 {
374   GEOM::GEOM_Object_var aGEOMObject;
375
376   //Set a not done flag
377   GetOperations()->SetNotDone();
378
379   if (theFace == NULL) return aGEOMObject._retn();
380
381   //Get the reference face
382
383   Handle(GEOM_Object) aRef = GetOperations()->GetEngine()->GetObject
384     (theFace->GetStudyID(), theFace->GetEntry());
385   if (aRef.IsNull()) return aGEOMObject._retn();
386
387   //Create the plane
388
389   Handle(GEOM_Object) anObject =
390     GetOperations()->MakePlaneFace(aRef, theTrimSize);
391   if (!GetOperations()->IsDone() || anObject.IsNull())
392     return aGEOMObject._retn();
393
394   return GetObject(anObject);
395 }
396
397
398 //=============================================================================
399 /*!
400  *  MakeMarker
401  */
402 //=============================================================================
403 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeMarker
404   (CORBA::Double theOX , CORBA::Double theOY , CORBA::Double theOZ,
405    CORBA::Double theXDX, CORBA::Double theXDY, CORBA::Double theXDZ,
406    CORBA::Double theYDX, CORBA::Double theYDY, CORBA::Double theYDZ)
407 {
408   GEOM::GEOM_Object_var aGEOMObject;
409
410   //Set a not done flag
411   GetOperations()->SetNotDone();
412
413   //Create the point
414   Handle(GEOM_Object) anObject = GetOperations()->MakeMarker(theOX , theOY , theOZ,
415                                                              theXDX, theXDY, theXDZ,
416                                                              theYDX, theYDY, theYDZ);
417   if (!GetOperations()->IsDone() || anObject.IsNull())
418     return aGEOMObject._retn();
419
420   return GetObject(anObject);
421 }
422
423 //=============================================================================
424 /*!
425  *  MakeTangentPlaneOnFace
426  */
427 //=============================================================================
428
429 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeTangentPlaneOnFace
430                      (GEOM::GEOM_Object_ptr theFace, 
431                       CORBA::Double theParameterU,
432                       CORBA::Double theParameterV,
433                       CORBA::Double theTrimSize)
434 {
435   GEOM::GEOM_Object_var aGEOMObject;
436
437   //Set a not done flag
438   GetOperations()->SetNotDone();
439
440   if (theFace == NULL) return aGEOMObject._retn();
441
442   //Get the reference face
443
444   Handle(GEOM_Object) aRef = GetOperations()->GetEngine()->GetObject
445     (theFace->GetStudyID(), theFace->GetEntry());
446   if (aRef.IsNull()) return aGEOMObject._retn();
447
448   //Create the plane
449
450   Handle(GEOM_Object) anObject =
451     GetOperations()->MakeTangentPlaneOnFace(aRef, theParameterU,theParameterV,theTrimSize);
452   if (!GetOperations()->IsDone() || anObject.IsNull())
453     return aGEOMObject._retn();
454
455   return GetObject(anObject);
456 }
457