1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
22 #include "GEOM_I3DPrimOperations_i.hh"
24 #include "utilities.h"
26 #include "Utils_ExceptHandlers.hxx"
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
31 //=============================================================================
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)
39 MESSAGE("GEOM_I3DPrimOperations_i::GEOM_I3DPrimOperations_i");
42 //=============================================================================
46 //=============================================================================
47 GEOM_I3DPrimOperations_i::~GEOM_I3DPrimOperations_i()
49 MESSAGE("GEOM_I3DPrimOperations_i::~GEOM_I3DPrimOperations_i");
53 //=============================================================================
57 //=============================================================================
58 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeBoxDXDYDZ (CORBA::Double theDX,
62 GEOM::GEOM_Object_var aGEOMObject;
65 GetOperations()->SetNotDone();
68 Handle(GEOM_Object) anObject = GetOperations()->MakeBoxDXDYDZ(theDX, theDY, theDZ);
69 if (!GetOperations()->IsDone() || anObject.IsNull())
70 return aGEOMObject._retn();
72 return GetObject(anObject);
75 //=============================================================================
79 //=============================================================================
80 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeBoxTwoPnt
81 (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2)
83 GEOM::GEOM_Object_var aGEOMObject;
86 GetOperations()->SetNotDone();
88 if (thePnt1 == NULL || thePnt2 == NULL) return aGEOMObject._retn();
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());
96 if (aPnt1.IsNull() || aPnt2.IsNull()) return aGEOMObject._retn();
99 Handle(GEOM_Object) anObject = GetOperations()->MakeBoxTwoPnt(aPnt1, aPnt2);
100 if (!GetOperations()->IsDone() || anObject.IsNull())
101 return aGEOMObject._retn();
103 return GetObject(anObject);
106 //=============================================================================
110 //=============================================================================
111 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeCylinderRH (CORBA::Double theR,
114 GEOM::GEOM_Object_var aGEOMObject;
116 //Set a not done flag
117 GetOperations()->SetNotDone();
119 //Create the Cylinder
120 Handle(GEOM_Object) anObject = GetOperations()->MakeCylinderRH(theR, theH);
121 if (!GetOperations()->IsDone() || anObject.IsNull())
122 return aGEOMObject._retn();
124 return GetObject(anObject);
127 //=============================================================================
129 * MakeCylinderPntVecRH
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)
136 GEOM::GEOM_Object_var aGEOMObject;
138 //Set a not done flag
139 GetOperations()->SetNotDone();
141 if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
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());
149 if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
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();
156 return GetObject(anObject);
159 //=============================================================================
163 //=============================================================================
164 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeConeR1R2H (CORBA::Double theR1,
168 GEOM::GEOM_Object_var aGEOMObject;
170 //Set a not done flag
171 GetOperations()->SetNotDone();
174 Handle(GEOM_Object) anObject = GetOperations()->MakeConeR1R2H(theR1, theR2, theH);
175 if (!GetOperations()->IsDone() || anObject.IsNull())
176 return aGEOMObject._retn();
178 return GetObject(anObject);
181 //=============================================================================
183 * MakeConePntVecR1R2H
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)
190 GEOM::GEOM_Object_var aGEOMObject;
192 //Set a not done flag
193 GetOperations()->SetNotDone();
195 if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
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());
203 if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
206 Handle(GEOM_Object) anObject =
207 GetOperations()->MakeConePntVecR1R2H(aPnt, aVec, theR1, theR2, theH);
208 if (!GetOperations()->IsDone() || anObject.IsNull())
209 return aGEOMObject._retn();
211 return GetObject(anObject);
214 //=============================================================================
218 //=============================================================================
219 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeSphereR (CORBA::Double theR)
221 GEOM::GEOM_Object_var aGEOMObject;
223 //Set a not done flag
224 GetOperations()->SetNotDone();
227 Handle(GEOM_Object) anObject = GetOperations()->MakeSphereR(theR);
228 if (!GetOperations()->IsDone() || anObject.IsNull())
229 return aGEOMObject._retn();
231 return GetObject(anObject);
234 //=============================================================================
238 //=============================================================================
239 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeSpherePntR
240 (GEOM::GEOM_Object_ptr thePnt, CORBA::Double theR)
242 GEOM::GEOM_Object_var aGEOMObject;
244 //Set a not done flag
245 GetOperations()->SetNotDone();
247 if (thePnt == NULL) return aGEOMObject._retn();
249 //Get the reference point
250 Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject
251 (thePnt->GetStudyID(), thePnt->GetEntry());
253 if (aPnt.IsNull()) return aGEOMObject._retn();
256 Handle(GEOM_Object) anObject =
257 GetOperations()->MakeSpherePntR(aPnt, theR);
258 if (!GetOperations()->IsDone() || anObject.IsNull())
259 return aGEOMObject._retn();
261 return GetObject(anObject);
264 //=============================================================================
268 //=============================================================================
269 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeTorusRR
270 (CORBA::Double theRMajor, CORBA::Double theRMinor)
272 GEOM::GEOM_Object_var aGEOMObject;
274 //Set a not done flag
275 GetOperations()->SetNotDone();
278 Handle(GEOM_Object) anObject =
279 GetOperations()->MakeTorusRR(theRMajor, theRMinor);
280 if (!GetOperations()->IsDone() || anObject.IsNull())
281 return aGEOMObject._retn();
283 return GetObject(anObject);
286 //=============================================================================
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)
295 GEOM::GEOM_Object_var aGEOMObject;
297 //Set a not done flag
298 GetOperations()->SetNotDone();
300 if (thePnt == NULL || theVec == NULL) return aGEOMObject._retn();
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());
308 if (aPnt.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
311 Handle(GEOM_Object) anObject =
312 GetOperations()->MakeTorusPntVecRR(aPnt, aVec, theRMajor, theRMinor);
313 if (!GetOperations()->IsDone() || anObject.IsNull())
314 return aGEOMObject._retn();
316 return GetObject(anObject);
319 //=============================================================================
323 //=============================================================================
324 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakePrismVecH
325 (GEOM::GEOM_Object_ptr theBase, GEOM::GEOM_Object_ptr theVec,
328 GEOM::GEOM_Object_var aGEOMObject;
330 //Set a not done flag
331 GetOperations()->SetNotDone();
333 if (theBase == NULL || theVec == NULL) return aGEOMObject._retn();
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());
341 if (aBase.IsNull() || aVec.IsNull()) return aGEOMObject._retn();
344 Handle(GEOM_Object) anObject =
345 GetOperations()->MakePrismVecH(aBase, aVec, theH);
346 if (!GetOperations()->IsDone() || anObject.IsNull())
347 return aGEOMObject._retn();
349 return GetObject(anObject);
352 //=============================================================================
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)
362 GEOM::GEOM_Object_var aGEOMObject;
364 //Set a not done flag
365 GetOperations()->SetNotDone();
367 if (theBase == NULL || thePoint1 == NULL || thePoint2 == NULL)
368 return aGEOMObject._retn();
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());
378 if (aBase.IsNull() || aPoint1.IsNull() || aPoint2.IsNull())
379 return aGEOMObject._retn();
382 Handle(GEOM_Object) anObject =
383 GetOperations()->MakePrismTwoPnt(aBase, aPoint1, aPoint2);
384 if (!GetOperations()->IsDone() || anObject.IsNull())
385 return aGEOMObject._retn();
387 return GetObject(anObject);
390 //=============================================================================
394 //=============================================================================
395 GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakePipe
396 (GEOM::GEOM_Object_ptr theBase, GEOM::GEOM_Object_ptr thePath)
398 GEOM::GEOM_Object_var aGEOMObject;
400 //Set a not done flag
401 GetOperations()->SetNotDone();
403 if (theBase == NULL || thePath == NULL) return aGEOMObject._retn();
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());
411 if (aBase.IsNull() || aPath.IsNull()) return aGEOMObject._retn();
414 Handle(GEOM_Object) anObject =
415 GetOperations()->MakePipe(aBase, aPath);
416 if (!GetOperations()->IsDone() || anObject.IsNull())
417 return aGEOMObject._retn();
419 return GetObject(anObject);
422 //=============================================================================
424 * MakeRevolutionAxisAngle
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)
431 GEOM::GEOM_Object_var aGEOMObject;
433 //Set a not done flag
434 GetOperations()->SetNotDone();
436 if (theBase == NULL || theAxis == NULL) return aGEOMObject._retn();
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());
444 if (aBase.IsNull() || anAxis.IsNull()) return aGEOMObject._retn();
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();
452 return GetObject(anObject);
455 //=============================================================================
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)
467 GEOM::GEOM_Object_var aGEOMObject;
469 //Set a not done flag
470 GetOperations()->SetNotDone();
472 if (theShape == NULL) return aGEOMObject._retn();
474 //Get the reference objects
475 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
476 (theShape->GetStudyID(), theShape->GetEntry());
478 if (aShape.IsNull()) return aGEOMObject._retn();
481 Handle(GEOM_Object) anObject = GetOperations()->MakeFilling(aShape, theMinDeg, theMaxDeg, theTol2D, theTol3D, theNbIter);
482 if (!GetOperations()->IsDone() || anObject.IsNull())
483 return aGEOMObject._retn();
485 return GetObject(anObject);
488 //=============================================================================
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)
498 GEOM::GEOM_Object_var aGEOMObject;
500 //Set a not done flag
501 GetOperations()->SetNotDone();
502 Handle(TColStd_HSequenceOfTransient) aSeqSections = new TColStd_HSequenceOfTransient;
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());
512 aSeqSections->Append(aSh);
514 if(!aSeqSections->Length())
515 return aGEOMObject._retn();
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();
523 return GetObject(anObject);
526 //=============================================================================
528 * MakePipeWithDifferentSections
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)
537 GEOM::GEOM_Object_var aGEOMObject;
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;
546 aNbBases = theBases.length();
547 aNbLocs = theLocations.length();
549 if( aNbLocs && aNbBases != aNbLocs)
550 return aGEOMObject._retn();
552 Handle(GEOM_Object) aPath = GetOperations()->GetEngine()->GetObject
553 (thePath->GetStudyID(), thePath->GetEntry());
555 return aGEOMObject._retn();
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());
565 Handle(GEOM_Object) aLoc = GetOperations()->GetEngine()->GetObject
566 (theLocations[ind]->GetStudyID(), theLocations[ind]->GetEntry());
569 aSeqLocations->Append(aLoc);
571 aSeqBases->Append(aBase);
573 if(!aSeqBases->Length())
574 return aGEOMObject._retn();
577 Handle(GEOM_Object) anObject =
578 GetOperations()->MakePipeWithDifferentSections(aSeqBases,aSeqLocations ,aPath,
579 theWithContact,theWithCorrections);
580 if (!GetOperations()->IsDone() || anObject.IsNull())
581 return aGEOMObject._retn();
583 return GetObject(anObject);