Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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  *  MakePointOnLinesIntersection
111  */
112 //=============================================================================
113 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnLinesIntersection
114                   (GEOM::GEOM_Object_ptr theLine1,  GEOM::GEOM_Object_ptr theLine2)
115 {
116   GEOM::GEOM_Object_var aGEOMObject;
117
118   //Set a not done flag
119   GetOperations()->SetNotDone();
120
121   if (theLine1 == NULL || theLine2 == NULL) return aGEOMObject._retn();
122
123   //Get the reference Lines
124
125   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
126     (theLine1->GetStudyID(), theLine1->GetEntry());
127   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
128     (theLine2->GetStudyID(), theLine2->GetEntry());
129   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
130
131   //Create the point
132
133   Handle(GEOM_Object) anObject =
134     GetOperations()->MakePointOnLinesIntersection(aRef1, aRef2);
135   if (!GetOperations()->IsDone() || anObject.IsNull())
136     return aGEOMObject._retn();
137
138   return GetObject(anObject);
139 }
140
141 //=============================================================================
142 /*!
143  *  MakePointOnCurve
144  */
145 //=============================================================================
146 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePointOnCurve
147                   (GEOM::GEOM_Object_ptr theCurve,  CORBA::Double theParameter)
148 {
149   GEOM::GEOM_Object_var aGEOMObject;
150
151   //Set a not done flag
152   GetOperations()->SetNotDone();
153
154   if (theCurve == NULL) return aGEOMObject._retn();
155
156   //Get the reference curve
157
158   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
159     (theCurve->GetStudyID(), theCurve->GetEntry());
160   if (aRefernce.IsNull()) return aGEOMObject._retn();
161
162   //Create the point
163
164   Handle(GEOM_Object) anObject =
165     GetOperations()->MakePointOnCurve(aRefernce, theParameter);
166   if (!GetOperations()->IsDone() || anObject.IsNull())
167     return aGEOMObject._retn();
168
169   return GetObject(anObject);
170 }
171
172 //=============================================================================
173 /*!
174  *  MakeTangentOnCurve
175  */
176 //=============================================================================
177 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeTangentOnCurve
178                   (GEOM::GEOM_Object_ptr theCurve,  CORBA::Double theParameter)
179 {
180   GEOM::GEOM_Object_var aGEOMObject;
181
182   //Set a not done flag
183   GetOperations()->SetNotDone();
184
185   if (theCurve == NULL) return aGEOMObject._retn();
186
187   //Get the reference curve
188
189   Handle(GEOM_Object) aRefernce = GetOperations()->GetEngine()->GetObject
190     (theCurve->GetStudyID(), theCurve->GetEntry());
191   if (aRefernce.IsNull()) return aGEOMObject._retn();
192
193   //Create the point
194
195   Handle(GEOM_Object) anObject =
196     GetOperations()->MakeTangentOnCurve(aRefernce, theParameter);
197   if (!GetOperations()->IsDone() || anObject.IsNull())
198     return aGEOMObject._retn();
199
200   return GetObject(anObject);
201 }
202
203
204 //=============================================================================
205 /*!
206  *  MakeVectorDXDYDZ
207  */
208 //=============================================================================
209 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeVectorDXDYDZ
210   (CORBA::Double theDX, CORBA::Double theDY, CORBA::Double theDZ)
211 {
212   GEOM::GEOM_Object_var aGEOMObject;
213
214   //Set a not done flag
215   GetOperations()->SetNotDone();
216
217   //Create the Vector
218
219   Handle(GEOM_Object) anObject = GetOperations()->MakeVectorDXDYDZ(theDX, theDY, theDZ);
220   if (!GetOperations()->IsDone() || anObject.IsNull())
221     return aGEOMObject._retn();
222
223   return GetObject(anObject);
224 }
225
226 //=============================================================================
227 /*!
228  *  MakeVectorTwoPnt
229  */
230 //=============================================================================
231 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeVectorTwoPnt
232                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
233 {
234   GEOM::GEOM_Object_var aGEOMObject;
235
236   //Set a not done flag
237   GetOperations()->SetNotDone();
238
239   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
240
241   //Get the reference points
242
243   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
244     (thePnt1->GetStudyID(), thePnt1->GetEntry());
245   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
246     (thePnt2->GetStudyID(), thePnt2->GetEntry());
247   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
248
249   //Create the vector
250
251   Handle(GEOM_Object) anObject =
252     GetOperations()->MakeVectorTwoPnt(aRef1, aRef2);
253   if (!GetOperations()->IsDone() || anObject.IsNull())
254     return aGEOMObject._retn();
255
256   return GetObject(anObject);
257 }
258
259
260 //=============================================================================
261 /*!
262  *  MakeLine
263  */
264 //=============================================================================
265 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeLine
266                    (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theDir)
267 {
268   GEOM::GEOM_Object_var aGEOMObject;
269
270   //Set a not done flag
271   GetOperations()->SetNotDone();
272
273   if (thePnt == NULL || theDir == NULL) return aGEOMObject._retn();
274
275   //Get the reference objects
276
277   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
278     (thePnt->GetStudyID(), thePnt->GetEntry());
279   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
280     (theDir->GetStudyID(), theDir->GetEntry());
281   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
282
283   //Create the Line
284
285   Handle(GEOM_Object) anObject =
286     GetOperations()->MakeLine(aRef1, aRef2);
287   if (!GetOperations()->IsDone() || anObject.IsNull())
288     return aGEOMObject._retn();
289
290   return GetObject(anObject);
291 }
292
293 //=============================================================================
294 /*!
295  *  MakeLineTwoPnt
296  */
297 //=============================================================================
298 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeLineTwoPnt
299                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
300 {
301   GEOM::GEOM_Object_var aGEOMObject;
302
303   //Set a not done flag
304   GetOperations()->SetNotDone();
305
306   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
307
308   //Get the reference points
309
310   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
311     (thePnt1->GetStudyID(), thePnt1->GetEntry());
312   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
313     (thePnt2->GetStudyID(), thePnt2->GetEntry());
314   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
315
316   //Create the Line
317
318   Handle(GEOM_Object) anObject =
319     GetOperations()->MakeLineTwoPnt(aRef1, aRef2);
320   if (!GetOperations()->IsDone() || anObject.IsNull())
321     return aGEOMObject._retn();
322
323   return GetObject(anObject);
324 }
325
326 //=============================================================================
327 /*!
328  *  MakeLineTwoFaces
329  */
330 //=============================================================================
331 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeLineTwoFaces
332                  (GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
333 {
334   GEOM::GEOM_Object_var aGEOMObject;
335
336   //Set a not done flag
337   GetOperations()->SetNotDone();
338
339   if (theFace1 == NULL || theFace2 == NULL) return aGEOMObject._retn();
340
341   //Get the reference points
342
343   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
344     (theFace1->GetStudyID(), theFace1->GetEntry());
345   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
346     (theFace2->GetStudyID(), theFace2->GetEntry());
347   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
348
349   //Create the Line
350
351   Handle(GEOM_Object) anObject =
352     GetOperations()->MakeLineTwoFaces(aRef1, aRef2);
353   if (!GetOperations()->IsDone() || anObject.IsNull())
354     return aGEOMObject._retn();
355
356   return GetObject(anObject);
357 }
358
359 //=============================================================================
360 /*!
361  *  MakePlanePntVec
362  */
363 //=============================================================================
364 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlanePntVec
365                  (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
366                   CORBA::Double theTrimSize)
367 {
368   GEOM::GEOM_Object_var aGEOMObject;
369
370   //Set a not done flag
371   GetOperations()->SetNotDone();
372
373   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
374
375   //Get the references
376
377   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
378     (thePnt->GetStudyID(), thePnt->GetEntry());
379   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
380     (theVec->GetStudyID(), theVec->GetEntry());
381   if (aRef1.IsNull() || aRef2.IsNull()) return aGEOMObject._retn();
382
383   //Create the plane
384
385   Handle(GEOM_Object) anObject =
386     GetOperations()->MakePlanePntVec(aRef1, aRef2, theTrimSize);
387   if (!GetOperations()->IsDone() || anObject.IsNull())
388     return aGEOMObject._retn();
389
390   return GetObject(anObject);
391 }
392
393 //=============================================================================
394 /*!
395  *  MakePlaneThreePnt
396  */
397 //=============================================================================
398 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlaneThreePnt
399                  (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
400                   GEOM::GEOM_Object_ptr thePnt3, CORBA::Double theTrimSize)
401 {
402   GEOM::GEOM_Object_var aGEOMObject;
403
404   //Set a not done flag
405   GetOperations()->SetNotDone();
406
407   if (thePnt1 == NULL || thePnt2 == NULL || thePnt3 == NULL)
408     return aGEOMObject._retn();
409
410   //Get the reference points
411
412   Handle(GEOM_Object) aRef1 = GetOperations()->GetEngine()->GetObject
413     (thePnt1->GetStudyID(), thePnt1->GetEntry());
414   Handle(GEOM_Object) aRef2 = GetOperations()->GetEngine()->GetObject
415     (thePnt2->GetStudyID(), thePnt2->GetEntry());
416   Handle(GEOM_Object) aRef3 = GetOperations()->GetEngine()->GetObject
417     (thePnt3->GetStudyID(), thePnt3->GetEntry());
418   if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull())
419     return aGEOMObject._retn();
420
421   //Create the plane
422
423   Handle(GEOM_Object) anObject =
424     GetOperations()->MakePlaneThreePnt(aRef1, aRef2, aRef3, theTrimSize);
425   if (!GetOperations()->IsDone() || anObject.IsNull())
426     return aGEOMObject._retn();
427
428   return GetObject(anObject);
429 }
430
431 //=============================================================================
432 /*!
433  *  MakePlaneFace
434  */
435 //=============================================================================
436 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakePlaneFace
437                      (GEOM::GEOM_Object_ptr theFace, CORBA::Double theTrimSize)
438 {
439   GEOM::GEOM_Object_var aGEOMObject;
440
441   //Set a not done flag
442   GetOperations()->SetNotDone();
443
444   if (theFace == NULL) return aGEOMObject._retn();
445
446   //Get the reference face
447
448   Handle(GEOM_Object) aRef = GetOperations()->GetEngine()->GetObject
449     (theFace->GetStudyID(), theFace->GetEntry());
450   if (aRef.IsNull()) return aGEOMObject._retn();
451
452   //Create the plane
453
454   Handle(GEOM_Object) anObject =
455     GetOperations()->MakePlaneFace(aRef, theTrimSize);
456   if (!GetOperations()->IsDone() || anObject.IsNull())
457     return aGEOMObject._retn();
458
459   return GetObject(anObject);
460 }
461
462
463 //=============================================================================
464 /*!
465  *  MakeMarker
466  */
467 //=============================================================================
468 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeMarker
469   (CORBA::Double theOX , CORBA::Double theOY , CORBA::Double theOZ,
470    CORBA::Double theXDX, CORBA::Double theXDY, CORBA::Double theXDZ,
471    CORBA::Double theYDX, CORBA::Double theYDY, CORBA::Double theYDZ)
472 {
473   GEOM::GEOM_Object_var aGEOMObject;
474
475   //Set a not done flag
476   GetOperations()->SetNotDone();
477
478   //Create the point
479   Handle(GEOM_Object) anObject = GetOperations()->MakeMarker(theOX , theOY , theOZ,
480                                                              theXDX, theXDY, theXDZ,
481                                                              theYDX, theYDY, theYDZ);
482   if (!GetOperations()->IsDone() || anObject.IsNull())
483     return aGEOMObject._retn();
484
485   return GetObject(anObject);
486 }
487
488 //=============================================================================
489 /*!
490  *  MakeTangentPlaneOnFace
491  */
492 //=============================================================================
493
494 GEOM::GEOM_Object_ptr GEOM_IBasicOperations_i::MakeTangentPlaneOnFace
495                      (GEOM::GEOM_Object_ptr theFace, 
496                       CORBA::Double theParameterU,
497                       CORBA::Double theParameterV,
498                       CORBA::Double theTrimSize)
499 {
500   GEOM::GEOM_Object_var aGEOMObject;
501
502   //Set a not done flag
503   GetOperations()->SetNotDone();
504
505   if (theFace == NULL) return aGEOMObject._retn();
506
507   //Get the reference face
508
509   Handle(GEOM_Object) aRef = GetOperations()->GetEngine()->GetObject
510     (theFace->GetStudyID(), theFace->GetEntry());
511   if (aRef.IsNull()) return aGEOMObject._retn();
512
513   //Create the plane
514
515   Handle(GEOM_Object) anObject =
516     GetOperations()->MakeTangentPlaneOnFace(aRef, theParameterU,theParameterV,theTrimSize);
517   if (!GetOperations()->IsDone() || anObject.IsNull())
518     return aGEOMObject._retn();
519
520   return GetObject(anObject);
521 }
522