Salome HOME
PAL12781: EDF: different result between Working Plane and LCS. Implement and use...
[modules/geom.git] / src / GEOM_I / GEOM_I3DPrimOperations_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_I3DPrimOperations_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_I3DPrimOperations_i::GEOM_I3DPrimOperations_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, ::GEOMImpl_I3DPrimOperations* theImpl)
37 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
38 {
39   MESSAGE("GEOM_I3DPrimOperations_i::GEOM_I3DPrimOperations_i");
40 }
41
42 //=============================================================================
43 /*!
44  *  destructor
45  */
46 //=============================================================================
47 GEOM_I3DPrimOperations_i::~GEOM_I3DPrimOperations_i()
48 {
49   MESSAGE("GEOM_I3DPrimOperations_i::~GEOM_I3DPrimOperations_i");
50 }
51
52
53 //=============================================================================
54 /*!
55  *  MakeBoxDXDYDZ
56  */
57 //=============================================================================
58 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeBoxDXDYDZ (CORBA::Double theDX,
59                                                                CORBA::Double theDY,
60                                                                CORBA::Double theDZ)
61 {
62   GEOM::GEOM_Object_var aGEOMObject;
63
64   //Set a not done flag
65   GetOperations()->SetNotDone();
66    
67   //Create the Box
68   Handle(GEOM_Object) anObject = GetOperations()->MakeBoxDXDYDZ(theDX, theDY, theDZ);
69   if (!GetOperations()->IsDone() || anObject.IsNull())
70     return aGEOMObject._retn();
71  
72   return GetObject(anObject);
73 }
74
75 //=============================================================================
76 /*!
77  *  MakeBoxTwoPnt
78  */
79 //=============================================================================
80 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeBoxTwoPnt
81                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
82 {
83   GEOM::GEOM_Object_var aGEOMObject;
84
85   //Set a not done flag
86   GetOperations()->SetNotDone();
87
88   if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
89
90   //Get the reference points
91   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
92     (thePnt1->GetStudyID(), thePnt1->GetEntry());
93   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
94     (thePnt2->GetStudyID(), thePnt2->GetEntry());
95
96   if (aPnt1.IsNull() || aPnt2.IsNull()) return aGEOMObject._retn();
97
98   //Create the Box
99   Handle(GEOM_Object) anObject = GetOperations()->MakeBoxTwoPnt(aPnt1, aPnt2);
100   if (!GetOperations()->IsDone() || anObject.IsNull())
101     return aGEOMObject._retn();
102
103   return GetObject(anObject);
104 }
105
106 //=============================================================================
107 /*!
108  *  MakeCylinderRH
109  */
110 //=============================================================================
111 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeCylinderRH (CORBA::Double theR,
112                                                                 CORBA::Double theH)
113 {
114   GEOM::GEOM_Object_var aGEOMObject;
115
116   //Set a not done flag
117   GetOperations()->SetNotDone();
118
119   //Create the Cylinder
120   Handle(GEOM_Object) anObject = GetOperations()->MakeCylinderRH(theR, theH);
121   if (!GetOperations()->IsDone() || anObject.IsNull())
122     return aGEOMObject._retn();
123
124   return GetObject(anObject);
125 }
126
127 //=============================================================================
128 /*!
129  *  MakeCylinderPntVecRH
130  */
131 //=============================================================================
132 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeCylinderPntVecRH
133                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
134                        CORBA::Double theR, CORBA::Double theH)
135 {
136   GEOM::GEOM_Object_var aGEOMObject;
137
138   //Set a not done flag
139   GetOperations()->SetNotDone();
140
141   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
142
143   //Get the reference points
144   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
145     (thePnt->GetStudyID(), thePnt->GetEntry());
146   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
147     (theVec->GetStudyID(), theVec->GetEntry());
148
149   if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
150
151   //Create the Cylinder
152   Handle(GEOM_Object) anObject = GetOperations()->MakeCylinderPntVecRH(aPnt, aVec, theR, theH);
153   if (!GetOperations()->IsDone() || anObject.IsNull())
154     return aGEOMObject._retn();
155
156   return GetObject(anObject);
157 }
158
159 //=============================================================================
160 /*!
161  *  MakeConeR1R2H
162  */
163 //=============================================================================
164 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeConeR1R2H (CORBA::Double theR1,
165                                                                CORBA::Double theR2,
166                                                                CORBA::Double theH)
167 {
168   GEOM::GEOM_Object_var aGEOMObject;
169
170   //Set a not done flag
171   GetOperations()->SetNotDone();
172
173   //Create the Cone
174   Handle(GEOM_Object) anObject = GetOperations()->MakeConeR1R2H(theR1, theR2, theH);
175   if (!GetOperations()->IsDone() || anObject.IsNull())
176     return aGEOMObject._retn();
177
178   return GetObject(anObject);
179 }
180
181 //=============================================================================
182 /*!
183  *  MakeConePntVecR1R2H
184  */
185 //=============================================================================
186 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeConePntVecR1R2H
187                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
188                        CORBA::Double theR1, CORBA::Double theR2, CORBA::Double theH)
189 {
190   GEOM::GEOM_Object_var aGEOMObject;
191
192   //Set a not done flag
193   GetOperations()->SetNotDone();
194
195   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
196
197   //Get the reference points
198   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
199     (thePnt->GetStudyID(), thePnt->GetEntry());
200   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
201     (theVec->GetStudyID(), theVec->GetEntry());
202
203   if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
204
205   //Create the Cone
206   Handle(GEOM_Object) anObject =
207       GetOperations()->MakeConePntVecR1R2H(aPnt, aVec, theR1, theR2, theH);
208   if (!GetOperations()->IsDone() || anObject.IsNull())
209     return aGEOMObject._retn();
210
211   return GetObject(anObject);
212 }
213
214 //=============================================================================
215 /*!
216  *  MakeSphereR
217  */
218 //=============================================================================
219 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeSphereR (CORBA::Double theR)
220 {
221   GEOM::GEOM_Object_var aGEOMObject;
222
223   //Set a not done flag
224   GetOperations()->SetNotDone();
225
226   //Create the Cone
227   Handle(GEOM_Object) anObject = GetOperations()->MakeSphereR(theR);
228   if (!GetOperations()->IsDone() || anObject.IsNull())
229     return aGEOMObject._retn();
230
231   return GetObject(anObject);
232 }
233
234 //=============================================================================
235 /*!
236  *  MakeSpherePntR
237  */
238 //=============================================================================
239 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeSpherePntR
240                       (GEOM::GEOM_Object_ptr thePnt, CORBA::Double theR)
241 {
242   GEOM::GEOM_Object_var aGEOMObject;
243
244   //Set a not done flag
245   GetOperations()->SetNotDone();
246
247   if (thePnt == NULL) return aGEOMObject._retn();
248
249   //Get the reference point
250   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
251     (thePnt->GetStudyID(), thePnt->GetEntry());
252
253   if (aPnt.IsNull()) return aGEOMObject._retn();
254
255   //Create the Sphere
256   Handle(GEOM_Object) anObject =
257       GetOperations()->MakeSpherePntR(aPnt, theR);
258   if (!GetOperations()->IsDone() || anObject.IsNull())
259     return aGEOMObject._retn();
260
261   return GetObject(anObject);
262 }
263
264 //=============================================================================
265 /*!
266  *  MakeTorusRR
267  */
268 //=============================================================================
269 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeTorusRR
270                       (CORBA::Double theRMajor, CORBA::Double theRMinor)
271 {
272   GEOM::GEOM_Object_var aGEOMObject;
273
274   //Set a not done flag
275   GetOperations()->SetNotDone();
276
277   // Make Torus
278   Handle(GEOM_Object) anObject =
279     GetOperations()->MakeTorusRR(theRMajor, theRMinor);
280   if (!GetOperations()->IsDone() || anObject.IsNull())
281     return aGEOMObject._retn();
282
283   return GetObject(anObject);
284 }
285
286 //=============================================================================
287 /*!
288  *  MakeTorusPntVecRR
289  */
290 //=============================================================================
291 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeTorusPntVecRR
292                       (GEOM::GEOM_Object_ptr thePnt, GEOM::GEOM_Object_ptr theVec,
293                        CORBA::Double theRMajor, CORBA::Double theRMinor)
294 {
295   GEOM::GEOM_Object_var aGEOMObject;
296
297   //Set a not done flag
298   GetOperations()->SetNotDone();
299
300   if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
301
302   //Get the reference points
303   Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
304     (thePnt->GetStudyID(), thePnt->GetEntry());
305   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
306     (theVec->GetStudyID(), theVec->GetEntry());
307
308   if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
309
310   // Make Torus
311   Handle(GEOM_Object) anObject =
312     GetOperations()->MakeTorusPntVecRR(aPnt, aVec, theRMajor, theRMinor);
313   if (!GetOperations()->IsDone() || anObject.IsNull())
314     return aGEOMObject._retn();
315
316   return GetObject(anObject);
317 }
318
319 //=============================================================================
320 /*!
321  *  MakePrismVecH
322  */
323 //=============================================================================
324 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakePrismVecH
325                       (GEOM::GEOM_Object_ptr theBase, GEOM::GEOM_Object_ptr theVec,
326                        CORBA::Double theH)
327 {
328   GEOM::GEOM_Object_var aGEOMObject;
329
330   //Set a not done flag
331   GetOperations()->SetNotDone();
332
333   if (theBase == NULL || theVec == NULL) return aGEOMObject._retn();
334
335   //Get the reference objects
336   Handle(GEOM_Object) aBase = GetOperations()->GetEngine()->GetObject
337     (theBase->GetStudyID(), theBase->GetEntry());
338   Handle(GEOM_Object) aVec = GetOperations()->GetEngine()->GetObject
339     (theVec->GetStudyID(), theVec->GetEntry());
340
341   if (aBase.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
342
343   //Create the Prism
344   Handle(GEOM_Object) anObject =
345       GetOperations()->MakePrismVecH(aBase, aVec, theH);
346   if (!GetOperations()->IsDone() || anObject.IsNull())
347     return aGEOMObject._retn();
348
349   return GetObject(anObject);
350 }
351
352 //=============================================================================
353 /*!
354  *  MakePrismTwoPnt
355  */
356 //=============================================================================
357 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakePrismTwoPnt
358                                              (GEOM::GEOM_Object_ptr theBase,
359                                               GEOM::GEOM_Object_ptr thePoint1,
360                                               GEOM::GEOM_Object_ptr thePoint2)
361 {
362   GEOM::GEOM_Object_var aGEOMObject;
363
364   //Set a not done flag
365   GetOperations()->SetNotDone();
366
367   if (theBase == NULL || thePoint1 == NULL || thePoint2 == NULL)
368     return aGEOMObject._retn();
369
370   //Get the reference objects
371   Handle(GEOM_Object) aBase = GetOperations()->GetEngine()->GetObject
372     (theBase->GetStudyID(), theBase->GetEntry());
373   Handle(GEOM_Object) aPoint1 = GetOperations()->GetEngine()->GetObject
374     (thePoint1->GetStudyID(), thePoint1->GetEntry());
375   Handle(GEOM_Object) aPoint2 = GetOperations()->GetEngine()->GetObject
376     (thePoint2->GetStudyID(), thePoint2->GetEntry());
377
378   if (aBase.IsNull() || aPoint1.IsNull() || aPoint2.IsNull())
379     return aGEOMObject._retn();
380
381   //Create the Prism
382   Handle(GEOM_Object) anObject =
383     GetOperations()->MakePrismTwoPnt(aBase, aPoint1, aPoint2);
384   if (!GetOperations()->IsDone() || anObject.IsNull())
385     return aGEOMObject._retn();
386
387   return GetObject(anObject);
388 }
389
390 //=============================================================================
391 /*!
392  *  MakePipe
393  */
394 //=============================================================================
395 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakePipe
396                  (GEOM::GEOM_Object_ptr theBase, GEOM::GEOM_Object_ptr thePath)
397 {
398   GEOM::GEOM_Object_var aGEOMObject;
399
400   //Set a not done flag
401   GetOperations()->SetNotDone();
402
403   if (theBase == NULL || thePath == NULL) return aGEOMObject._retn();
404
405   //Get the reference objects
406   Handle(GEOM_Object) aBase = GetOperations()->GetEngine()->GetObject
407     (theBase->GetStudyID(), theBase->GetEntry());
408   Handle(GEOM_Object) aPath = GetOperations()->GetEngine()->GetObject
409     (thePath->GetStudyID(), thePath->GetEntry());
410
411   if (aBase.IsNull() || aPath.IsNull()) return aGEOMObject._retn();
412
413   //Create the Pipe
414   Handle(GEOM_Object) anObject =
415     GetOperations()->MakePipe(aBase, aPath);
416   if (!GetOperations()->IsDone() || anObject.IsNull())
417     return aGEOMObject._retn();
418
419   return GetObject(anObject);
420 }
421
422 //=============================================================================
423 /*!
424  *  MakeRevolutionAxisAngle
425  */
426 //=============================================================================
427 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeRevolutionAxisAngle
428                       (GEOM::GEOM_Object_ptr theBase, GEOM::GEOM_Object_ptr theAxis,
429                        CORBA::Double theAngle)
430 {
431   GEOM::GEOM_Object_var aGEOMObject;
432
433   //Set a not done flag
434   GetOperations()->SetNotDone();
435
436   if (theBase == NULL || theAxis == NULL) return aGEOMObject._retn();
437
438   //Get the reference objects
439   Handle(GEOM_Object) aBase = GetOperations()->GetEngine()->GetObject
440     (theBase->GetStudyID(), theBase->GetEntry());
441   Handle(GEOM_Object) anAxis = GetOperations()->GetEngine()->GetObject
442     (theAxis->GetStudyID(), theAxis->GetEntry());
443
444   if (aBase.IsNull() || anAxis.IsNull()) return aGEOMObject._retn();
445
446   //Create the Revolution
447   Handle(GEOM_Object) anObject =
448       GetOperations()->MakeRevolutionAxisAngle(aBase, anAxis, theAngle);
449   if (!GetOperations()->IsDone() || anObject.IsNull())
450     return aGEOMObject._retn();
451
452   return GetObject(anObject);
453 }
454
455 //=============================================================================
456 /*!
457  *  MakeFilling
458  */
459 //=============================================================================
460 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeFilling(GEOM::GEOM_Object_ptr theShape,
461                                                             CORBA::Long theMinDeg,
462                                                             CORBA::Long theMaxDeg,
463                                                             CORBA::Double theTol2D,
464                                                             CORBA::Double theTol3D,
465                                                             CORBA::Long theNbIter)
466 {
467   GEOM::GEOM_Object_var aGEOMObject;
468
469   //Set a not done flag
470   GetOperations()->SetNotDone();
471
472   if (theShape == NULL) return aGEOMObject._retn();
473
474   //Get the reference objects
475   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
476     (theShape->GetStudyID(), theShape->GetEntry());
477
478   if (aShape.IsNull()) return aGEOMObject._retn();
479
480   //Create the Solid
481   Handle(GEOM_Object) anObject = GetOperations()->MakeFilling(aShape, theMinDeg, theMaxDeg, theTol2D, theTol3D, theNbIter);
482   if (!GetOperations()->IsDone() || anObject.IsNull())
483     return aGEOMObject._retn();
484
485   return GetObject(anObject);
486 }
487
488 //=============================================================================
489 /*!
490  *  MakeThruSections
491  */
492 //=============================================================================
493 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeThruSections(const GEOM::ListOfGO& theSeqSections,
494                                                                  CORBA::Boolean theModeSolid,
495                                                                  CORBA::Double thePreci,
496                                                                  CORBA::Boolean theRuled)
497 {
498    GEOM::GEOM_Object_var aGEOMObject;
499
500   //Set a not done flag
501   GetOperations()->SetNotDone();
502   Handle(TColStd_HSequenceOfTransient) aSeqSections = new TColStd_HSequenceOfTransient;
503   int ind, aLen;
504
505   //Get the shapes
506   aLen = theSeqSections.length();
507   for (ind = 0; ind < aLen; ind++) {
508     if (theSeqSections[ind] == NULL) continue;
509     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
510       (theSeqSections[ind]->GetStudyID(), theSeqSections[ind]->GetEntry());
511     if (!aSh.IsNull())
512       aSeqSections->Append(aSh);
513   }
514   if(!aSeqSections->Length())
515     return aGEOMObject._retn();
516
517   // Make shell or solid
518   Handle(GEOM_Object) anObject =
519     GetOperations()->MakeThruSections(aSeqSections,theModeSolid,thePreci,theRuled);
520   if (!GetOperations()->IsDone() || anObject.IsNull())
521     return aGEOMObject._retn();
522
523   return GetObject(anObject);
524 }
525
526 //=============================================================================
527 /*!
528  *  MakePipeWithDifferentSections
529  */
530 //=============================================================================
531 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakePipeWithDifferentSections(const GEOM::ListOfGO& theBases,
532                                                                               const GEOM::ListOfGO& theLocations,
533                                                                               GEOM::GEOM_Object_ptr thePath,
534                                                                               CORBA::Boolean theWithContact,
535                                                                               CORBA::Boolean theWithCorrections)
536 {
537    GEOM::GEOM_Object_var aGEOMObject;
538
539   //Set a not done flag
540   GetOperations()->SetNotDone();
541   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
542   Handle(TColStd_HSequenceOfTransient) aSeqLocations = new TColStd_HSequenceOfTransient;
543   int ind=0, aNbBases =0,aNbLocs=0;
544   
545   //Get the shapes
546   aNbBases = theBases.length();
547   aNbLocs = theLocations.length();
548
549   if( aNbLocs &&  aNbBases != aNbLocs)
550     return aGEOMObject._retn();
551   
552    Handle(GEOM_Object) aPath = GetOperations()->GetEngine()->GetObject
553       (thePath->GetStudyID(), thePath->GetEntry());
554    if(aPath.IsNull())
555      return aGEOMObject._retn();
556
557   for (ind = 0; ind < aNbBases; ind++) {
558     if (theBases[ind] == NULL) continue;
559     Handle(GEOM_Object) aBase = GetOperations()->GetEngine()->GetObject(theBases[ind]->GetStudyID(), 
560                         theBases[ind]->GetEntry());
561     if(aBase.IsNull())
562       continue;
563     if(aNbLocs)
564     {
565       Handle(GEOM_Object) aLoc = GetOperations()->GetEngine()->GetObject
566         (theLocations[ind]->GetStudyID(), theLocations[ind]->GetEntry());
567       if(aLoc.IsNull())
568         continue;
569       aSeqLocations->Append(aLoc);
570     }
571     aSeqBases->Append(aBase);
572   }
573   if(!aSeqBases->Length())
574     return aGEOMObject._retn();
575
576   // Make pipe
577   Handle(GEOM_Object) anObject =
578     GetOperations()->MakePipeWithDifferentSections(aSeqBases,aSeqLocations ,aPath,
579                                                    theWithContact,theWithCorrections);
580   if (!GetOperations()->IsDone() || anObject.IsNull())
581     return aGEOMObject._retn();
582
583   return GetObject(anObject);
584 }