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