Salome HOME
f475de827f6ea049caa991d573a4e17543d69d5a
[modules/geom.git] / src / GEOM_I / GEOM_IBasicOperations_i.cc
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <Standard_Stream.hxx>
23
24 #include "GEOM_IBasicOperations_i.hh"
25
26 #include "utilities.h"
27 #include "OpUtil.hxx"
28 #include "Utils_ExceptHandlers.hxx"
29
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
32
33 //=============================================================================
34 /*!
35  *   constructor:
36  */
37 //=============================================================================
38 GEOM_IBasicOperations_i::GEOM_IBasicOperations_i (PortableServer::POA_ptr thePOA,
39                                                   GEOM::GEOM_Gen_ptr theEngine,
40                                                   ::GEOMImpl_IBasicOperations* theImpl)
41      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
42 {
43   MESSAGE("GEOM_IBasicOperations_i::GEOM_IBasicOperations_i");
44 }
45
46 //=============================================================================
47 /*!
48  *  destructor
49  */
50 //=============================================================================
51 GEOM_IBasicOperations_i::~GEOM_IBasicOperations_i()
52 {
53   MESSAGE("GEOM_IBasicOperations_i::~GEOM_IBasicOperations_i");
54 }
55
56
57 //=============================================================================
58 /*!
59  *  MakePointXYZ
60  */
61 //=============================================================================
62 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointXYZ
63   (CORBA::Double theX, CORBA::Double theY, CORBA::Double theZ)
64 {
65   GEOM::GEOM_Object_var aGEOMObject;
66
67   //Set a not done flag
68   GetOperations()->SetNotDone();
69
70    //Create the point
71
72   Handle(GEOM_Object) anObject = GetOperations()->MakePointXYZ(theX, theY, theZ);
73   if (!GetOperations()->IsDone() || anObject.IsNull())
74     return aGEOMObject._retn();
75
76   return GetObject(anObject);
77 }
78
79 //=============================================================================
80 /*!
81  *  MakePointWithReference
82  */
83 //=============================================================================
84 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointWithReference
85   (GEOM::GEOM_Object_ptr theReference, CORBA::Double theX, CORBA::Double theY, CORBA::Double theZ)
86 {
87   GEOM::GEOM_Object_var aGEOMObject;
88
89   //Set a not done flag
90   GetOperations()->SetNotDone();
91
92   if(theReference == NULL) return aGEOMObject._retn();
93
94   //Get the reference point
95
96   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
97     (theReference->GetStudyID(), theReference->GetEntry());
98   if (aRefernce.IsNull()) return aGEOMObject._retn();
99
100   //Create the point
101
102   Handle(GEOM_Object) anObject =
103     GetOperations()->MakePointWithReference(aRefernce, theX, theY, theZ);
104   if (!GetOperations()->IsDone() || anObject.IsNull())
105     return aGEOMObject._retn();
106
107   return GetObject(anObject);
108 }
109
110 //=============================================================================
111 /*!
112  *  MakePointOnLinesIntersection
113  */
114 //=============================================================================
115 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnLinesIntersection
116                   (GEOM::GEOM_Object_ptr theLine1,  GEOM::GEOM_Object_ptr theLine2)
117 {
118   GEOM::GEOM_Object_var aGEOMObject;
119
120   //Set a not done flag
121   GetOperations()->SetNotDone();
122
123   if (theLine1 == NULL || theLine2 == NULL) return aGEOMObject._retn();
124
125   //Get the reference Lines
126
127   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
128     (theLine1->GetStudyID(), theLine1->GetEntry());
129   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
130     (theLine2->GetStudyID(), theLine2->GetEntry());
131   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
132
133   //Create the point
134
135   Handle(GEOM_Object) anObject =
136     GetOperations()->MakePointOnLinesIntersection(aRef1, aRef2);
137   if (!GetOperations()->IsDone() || anObject.IsNull())
138     return aGEOMObject._retn();
139
140   return GetObject(anObject);
141 }
142
143
144 //=============================================================================
145 /*!
146  *  MakePointOnCurve
147  */
148 //=============================================================================
149 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnCurve
150                   (GEOM::GEOM_Object_ptr theCurve,  CORBA::Double theParameter)
151 {
152   GEOM::GEOM_Object_var aGEOMObject;
153
154   //Set a not done flag
155   GetOperations()->SetNotDone();
156
157   if (theCurve == NULL) return aGEOMObject._retn();
158
159   //Get the reference curve
160
161   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
162     (theCurve->GetStudyID(), theCurve->GetEntry());
163   if (aRefernce.IsNull()) return aGEOMObject._retn();
164
165   //Create the point
166
167   Handle(GEOM_Object) anObject =
168     GetOperations()->MakePointOnCurve(aRefernce, theParameter);
169   if (!GetOperations()->IsDone() || anObject.IsNull())
170     return aGEOMObject._retn();
171
172   return GetObject(anObject);
173 }
174
175
176 //=============================================================================
177 /*!
178  *  MakePointOnSurface
179  */
180 //=============================================================================
181 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnSurface
182                                              (GEOM::GEOM_Object_ptr theSurface,
183                                               CORBA::Double theUParameter,
184                                               CORBA::Double theVParameter)
185 {
186   GEOM::GEOM_Object_var aGEOMObject;
187
188   //Set a not done flag
189   GetOperations()->SetNotDone();
190
191   if (theSurface == NULL) return aGEOMObject._retn();
192
193   //Get the reference surface
194   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
195     (theSurface->GetStudyID(), theSurface->GetEntry());
196   if (aRefernce.IsNull()) return aGEOMObject._retn();
197
198   //Create the point
199   Handle(GEOM_Object) anObject =
200     GetOperations()->MakePointOnSurface(aRefernce, theUParameter, theVParameter);
201   if (!GetOperations()->IsDone() || anObject.IsNull())
202     return aGEOMObject._retn();
203
204   return GetObject(anObject);
205 }
206
207
208 //=============================================================================
209 /*!
210  *  MakeTangentOnCurve
211  */
212 //=============================================================================
213 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeTangentOnCurve
214                   (GEOM::GEOM_Object_ptr theCurve,  CORBA::Double theParameter)
215 {
216   GEOM::GEOM_Object_var aGEOMObject;
217
218   //Set a not done flag
219   GetOperations()->SetNotDone();
220
221   if (theCurve == NULL) return aGEOMObject._retn();
222
223   //Get the reference curve
224
225   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
226     (theCurve->GetStudyID(), theCurve->GetEntry());
227   if (aRefernce.IsNull()) return aGEOMObject._retn();
228
229   //Create the point
230
231   Handle(GEOM_Object) anObject =
232     GetOperations()->MakeTangentOnCurve(aRefernce, theParameter);
233   if (!GetOperations()->IsDone() || anObject.IsNull())
234     return aGEOMObject._retn();
235
236   return GetObject(anObject);
237 }
238
239
240 //=============================================================================
241 /*!
242  *  MakeVectorDXDYDZ
243  */
244 //=============================================================================
245 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeVectorDXDYDZ
246   (CORBA::Double theDX, CORBA::Double theDY, CORBA::Double theDZ)
247 {
248   GEOM::GEOM_Object_var aGEOMObject;
249
250   //Set a not done flag
251   GetOperations()->SetNotDone();
252
253   //Create the Vector
254
255   Handle(GEOM_Object) anObject = GetOperations()->MakeVectorDXDYDZ(theDX, theDY, theDZ);
256   if (!GetOperations()->IsDone() || anObject.IsNull())
257     return aGEOMObject._retn();
258
259   return GetObject(anObject);
260 }
261
262 //=============================================================================
263 /*!
264  *  MakeVectorTwoPnt
265  */
266 //=============================================================================
267 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeVectorTwoPnt
268                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
269 {
270   GEOM::GEOM_Object_var aGEOMObject;
271
272   //Set a not done flag
273   GetOperations()->SetNotDone();
274
275   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
276
277   //Get the reference points
278
279   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
280     (thePnt1->GetStudyID(), thePnt1->GetEntry());
281   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
282     (thePnt2->GetStudyID(), thePnt2->GetEntry());
283   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
284
285   //Create the vector
286
287   Handle(GEOM_Object) anObject =
288     GetOperations()->MakeVectorTwoPnt(aRef1, aRef2);
289   if (!GetOperations()->IsDone() || anObject.IsNull())
290     return aGEOMObject._retn();
291
292   return GetObject(anObject);
293 }
294
295
296 //=============================================================================
297 /*!
298  *  MakeLine
299  */
300 //=============================================================================
301 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeLine
302                    (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theDir)
303 {
304   GEOM::GEOM_Object_var aGEOMObject;
305
306   //Set a not done flag
307   GetOperations()->SetNotDone();
308
309   if (thePnt == NULL || theDir == NULL) return aGEOMObject._retn();
310
311   //Get the reference objects
312
313   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
314     (thePnt->GetStudyID(), thePnt->GetEntry());
315   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
316     (theDir->GetStudyID(), theDir->GetEntry());
317   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
318
319   //Create the Line
320
321   Handle(GEOM_Object) anObject =
322     GetOperations()->MakeLine(aRef1, aRef2);
323   if (!GetOperations()->IsDone() || anObject.IsNull())
324     return aGEOMObject._retn();
325
326   return GetObject(anObject);
327 }
328
329 //=============================================================================
330 /*!
331  *  MakeLineTwoPnt
332  */
333 //=============================================================================
334 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeLineTwoPnt
335                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
336 {
337   GEOM::GEOM_Object_var aGEOMObject;
338
339   //Set a not done flag
340   GetOperations()->SetNotDone();
341
342   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
343
344   //Get the reference points
345
346   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
347     (thePnt1->GetStudyID(), thePnt1->GetEntry());
348   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
349     (thePnt2->GetStudyID(), thePnt2->GetEntry());
350   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
351
352   //Create the Line
353
354   Handle(GEOM_Object) anObject =
355     GetOperations()->MakeLineTwoPnt(aRef1, aRef2);
356   if (!GetOperations()->IsDone() || anObject.IsNull())
357     return aGEOMObject._retn();
358
359   return GetObject(anObject);
360 }
361
362 //=============================================================================
363 /*!
364  *  MakeLineTwoFaces
365  */
366 //=============================================================================
367 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeLineTwoFaces
368                  (GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
369 {
370   GEOM::GEOM_Object_var aGEOMObject;
371
372   //Set a not done flag
373   GetOperations()->SetNotDone();
374
375   if (theFace1 == NULL || theFace2 == NULL) return aGEOMObject._retn();
376
377   //Get the reference points
378
379   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
380     (theFace1->GetStudyID(), theFace1->GetEntry());
381   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
382     (theFace2->GetStudyID(), theFace2->GetEntry());
383   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
384
385   //Create the Line
386
387   Handle(GEOM_Object) anObject =
388     GetOperations()->MakeLineTwoFaces(aRef1, aRef2);
389   if (!GetOperations()->IsDone() || anObject.IsNull())
390     return aGEOMObject._retn();
391
392   return GetObject(anObject);
393 }
394
395 //=============================================================================
396 /*!
397  *  MakePlanePntVec
398  */
399 //=============================================================================
400 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlanePntVec
401                  (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
402                   CORBA::Double theTrimSize)
403 {
404   GEOM::GEOM_Object_var aGEOMObject;
405
406   //Set a not done flag
407   GetOperations()->SetNotDone();
408
409   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
410
411   //Get the references
412
413   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
414     (thePnt->GetStudyID(), thePnt->GetEntry());
415   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
416     (theVec->GetStudyID(), theVec->GetEntry());
417   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
418
419   //Create the plane
420
421   Handle(GEOM_Object) anObject =
422     GetOperations()->MakePlanePntVec(aRef1, aRef2, theTrimSize);
423   if (!GetOperations()->IsDone() || anObject.IsNull())
424     return aGEOMObject._retn();
425
426   return GetObject(anObject);
427 }
428
429 //=============================================================================
430 /*!
431  *  MakePlaneThreePnt
432  */
433 //=============================================================================
434 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlaneThreePnt
435                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
436                   GEOM::GEOM_Object_ptr thePnt3, CORBA::Double theTrimSize)
437 {
438   GEOM::GEOM_Object_var aGEOMObject;
439
440   //Set a not done flag
441   GetOperations()->SetNotDone();
442
443   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL)
444     return aGEOMObject._retn();
445
446   //Get the reference points
447
448   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
449     (thePnt1->GetStudyID(), thePnt1->GetEntry());
450   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
451     (thePnt2->GetStudyID(), thePnt2->GetEntry());
452   Handle(GEOM_Object) aRef3 = GetOperations()->GetEngine()->GetObject
453     (thePnt3->GetStudyID(), thePnt3->GetEntry());
454   if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull())
455     return aGEOMObject._retn();
456
457   //Create the plane
458
459   Handle(GEOM_Object) anObject =
460     GetOperations()->MakePlaneThreePnt(aRef1, aRef2, aRef3, theTrimSize);
461   if (!GetOperations()->IsDone() || anObject.IsNull())
462     return aGEOMObject._retn();
463
464   return GetObject(anObject);
465 }
466
467 //=============================================================================
468 /*!
469  *  MakePlaneFace
470  */
471 //=============================================================================
472 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlaneFace
473                      (GEOM::GEOM_Object_ptr theFace, CORBA::Double theTrimSize)
474 {
475   GEOM::GEOM_Object_var aGEOMObject;
476
477   //Set a not done flag
478   GetOperations()->SetNotDone();
479
480   if (theFace == NULL) return aGEOMObject._retn();
481
482   //Get the reference face
483
484   Handle(GEOM_Object) aRef = GetOperations()->GetEngine()->GetObject
485     (theFace->GetStudyID(), theFace->GetEntry());
486   if (aRef.IsNull()) return aGEOMObject._retn();
487
488   //Create the plane
489
490   Handle(GEOM_Object) anObject =
491     GetOperations()->MakePlaneFace(aRef, theTrimSize);
492   if (!GetOperations()->IsDone() || anObject.IsNull())
493     return aGEOMObject._retn();
494
495   return GetObject(anObject);
496 }
497
498
499 //=============================================================================
500 /*!
501  *  MakeMarker
502  */
503 //=============================================================================
504 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeMarker
505   (CORBA::Double theOX , CORBA::Double theOY , CORBA::Double theOZ,
506    CORBA::Double theXDX, CORBA::Double theXDY, CORBA::Double theXDZ,
507    CORBA::Double theYDX, CORBA::Double theYDY, CORBA::Double theYDZ)
508 {
509   GEOM::GEOM_Object_var aGEOMObject;
510
511   //Set a not done flag
512   GetOperations()->SetNotDone();
513
514   //Create the point
515   Handle(GEOM_Object) anObject = GetOperations()->MakeMarker(theOX , theOY , theOZ,
516                                                              theXDX, theXDY, theXDZ,
517                                                              theYDX, theYDY, theYDZ);
518   if (!GetOperations()->IsDone() || anObject.IsNull())
519     return aGEOMObject._retn();
520
521   return GetObject(anObject);
522 }
523
524 //=============================================================================
525 /*!
526  *  MakeTangentPlaneOnFace
527  */
528 //=============================================================================
529
530 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeTangentPlaneOnFace
531                      (GEOM::GEOM_Object_ptr theFace, 
532                       CORBA::Double theParameterU,
533                       CORBA::Double theParameterV,
534                       CORBA::Double theTrimSize)
535 {
536   GEOM::GEOM_Object_var aGEOMObject;
537
538   //Set a not done flag
539   GetOperations()->SetNotDone();
540
541   if (theFace == NULL) return aGEOMObject._retn();
542
543   //Get the reference face
544
545   Handle(GEOM_Object) aRef = GetOperations()->GetEngine()->GetObject
546     (theFace->GetStudyID(), theFace->GetEntry());
547   if (aRef.IsNull()) return aGEOMObject._retn();
548
549   //Create the plane
550
551   Handle(GEOM_Object) anObject =
552     GetOperations()->MakeTangentPlaneOnFace(aRef, theParameterU,theParameterV,theTrimSize);
553   if (!GetOperations()->IsDone() || anObject.IsNull())
554     return aGEOMObject._retn();
555
556   return GetObject(anObject);
557 }
558