1 // GEOM GEOM : implementaion of GEOM_Gen.idl and GEOM_Shape.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GEOM_GEN_i.cc file
25 // Author : Lucien PIGNOLONI
30 #include "GEOM_Gen_i.hh"
32 #include "Partition_Spliter.hxx"
33 #include "Archimede_VolumeSection.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "utilities.h"
42 #include <Standard_Failure.hxx>
44 #include <gp_Circ.hxx>
46 #include <Geom_Plane.hxx>
47 #include <Geom_Line.hxx>
48 #include <GeomFill_Line.hxx>
49 #include <GeomFill_AppSurf.hxx>
50 #include <GeomFill_SectionGenerator.hxx>
51 #include <Geom_BSplineSurface.hxx>
52 #include <Geom_TrimmedCurve.hxx>
53 #include <GC_MakeArcOfCircle.hxx>
54 #include <GC_Root.hxx>
56 #include <BRepCheck_Analyzer.hxx>
57 #if OCC_VERSION_MAJOR >= 5
58 #include <BRepAlgo.hxx>
60 #include <BRepAlgoAPI.hxx>
62 #include <BRepAdaptor_Surface.hxx>
63 #include <BRepBuilderAPI_Copy.hxx>
64 #include <BRepAlgoAPI_Common.hxx>
65 #include <BRepAlgoAPI_Cut.hxx>
66 #include <BRepAlgoAPI_Fuse.hxx>
67 #include <BRepAlgoAPI_Section.hxx>
68 #include <BRepOffsetAPI_Sewing.hxx>
69 #include <BRepOffsetAPI_MakePipe.hxx>
71 #include <BRepBuilderAPI_MakeVertex.hxx>
72 #include <BRepBuilderAPI_MakeEdge.hxx>
73 #include <BRepBuilderAPI_MakeFace.hxx>
75 #include <BRepLib.hxx>
76 #include <BRepBndLib.hxx>
77 #include <Bnd_Box.hxx>
79 #include <BRepBuilderAPI_MakeShell.hxx>
80 #include <BRepPrim_Builder.hxx>
81 #include <BRepBuilderAPI_MakeSolid.hxx>
82 #include <BRepClass3d_SolidClassifier.hxx>
84 #include <BRepBuilderAPI_MakeWire.hxx>
85 #include <BRepBuilderAPI_Transform.hxx>
86 #include <BRepPrimAPI_MakeRevol.hxx>
87 #include <BRepPrimAPI_MakePrism.hxx>
88 #include <BRepPrimAPI_MakeTorus.hxx>
89 #include <BRepPrimAPI_MakeBox.hxx>
90 #include <BRepPrimAPI_MakeSphere.hxx>
91 #include <BRepPrimAPI_MakeCylinder.hxx>
92 #include <BRepPrimAPI_MakeCone.hxx>
93 #include <BRepFilletAPI_MakeFillet.hxx>
94 #include <BRepFilletAPI_MakeChamfer.hxx>
95 #include <BRepTools.hxx>
96 #include <BRepTools_Quilt.hxx>
97 #include <BRep_Tool.hxx>
99 #include <GeomAPI_ProjectPointOnCurve.hxx>
101 #include <BRepGProp.hxx>
102 #include <GProp_GProps.hxx>
103 #include <Precision.hxx>
105 //VRV: OCC 4.0 migration
106 #include <STEPControl_Reader.hxx>
107 #include <IGESControl_Reader.hxx>
108 //VRV: OCC 4.0 migration
110 #include <IFSelect_ReturnStatus.hxx>
111 #include <TColStd_HSequenceOfTransient.hxx>
113 //VRV: OCC 4.0 migration
114 #include <IGESControl_Writer.hxx>
115 #include <IGESControl_Controller.hxx>
116 #include <STEPControl_Writer.hxx>
117 #include <Interface_Static.hxx>
118 //#include <STEPControlStd_StepModelType.hxx>
119 //VRV: OCC 4.0 migration
121 #include <TopoDS_Shape.hxx>
122 #include <TopAbs.hxx>
123 #include <TopoDS_Wire.hxx>
124 #include <TopoDS_Edge.hxx>
125 #include <TopoDS_Compound.hxx>
126 #include <TopoDS_Solid.hxx>
128 #include <TopExp.hxx>
129 #include <TopExp_Explorer.hxx>
130 #include <TCollection_ExtendedString.hxx>
131 #include <TopoDS_Iterator.hxx>
132 #include <TopTools_MapOfShape.hxx>
133 #include <TopTools_MapIteratorOfMapOfShape.hxx>
134 #include <TopTools_ListIteratorOfListOfShape.hxx>
135 #include <TopTools_Array1OfShape.hxx>
137 #include <IGESData_IGESEntity.hxx>
139 #include <TDF_Tool.hxx>
140 #include <TDF_Label.hxx>
141 #include <TDataStd_Name.hxx>
142 #include <TDataStd_Comment.hxx>
143 #include <TDF_Reference.hxx>
144 #include <TDF_Data.hxx>
145 #include <TNaming_Builder.hxx>
146 #include <TNaming_NamedShape.hxx>
147 #include <TNaming_Tool.hxx>
148 // #include <TDocStd_Owner.hxx>
150 #include "SALOMEDS_Tool.hxx"
151 #include "GEOMDS_Commands.hxx"
152 #include "GEOMDS_Explorer.hxx"
154 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
156 Standard_EXPORT static Standard_Boolean IsValid(const TopoDS_Shape& S) {
157 #if OCC_VERSION_MAJOR >= 5
158 return BRepAlgo::IsValid(S);
160 return BRepAlgoAPI::IsValid(S);
164 //============================================================================
165 // function : GEOM_Gen_i()
166 // purpose : constructor to be called for servant creation.
167 //============================================================================
168 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
169 PortableServer::POA_ptr poa,
170 PortableServer::ObjectId * contId,
171 const char *instanceName,
172 const char *interfaceName) :
173 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
176 _id = _poa->activate_object(_thisObj);
178 name_service = new SALOME_NamingService(_orb);
179 myOCAFApp = new GEOMDS_Application();
181 GetCurrentStudy(0);//for correct work of SuperVisor
186 //============================================================================
187 // function : ~GEOM_Gen_i()
188 // purpose : destructor
189 //============================================================================
190 GEOM_Gen_i::~GEOM_Gen_i() {
195 //============================================================================
196 // function : IORToLocalPersistentID()
198 //============================================================================
199 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
200 const char* IORString,
201 CORBA::Boolean isMultiFile,
202 CORBA::Boolean isASCII)
204 GEOM::GEOM_Shape_var aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(IORString));
205 if (!CORBA::is_nil(aShape)) {
206 return strdup(aShape->ShapeId());
212 //============================================================================
213 // function : LocalPersistentIDToIOR()
214 // purpose : Create/Load CORBA object from a persistent ref (an entry)
215 // : Used when a study is loaded
216 // : The IOR (IORName) of object created is returned
217 //============================================================================
218 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
219 const char* aLocalPersistentID,
220 CORBA::Boolean isMultiFile,
221 CORBA::Boolean isASCII)
223 SALOMEDS::Study_var myStudy = theSObject->GetStudy();
224 GetCurrentStudy(myStudy->StudyId());
225 Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(myStudyIDToDoc(myStudy->StudyId()));
226 CORBA::String_var aPersRefString = aLocalPersistentID;
228 /* For a GEOM::GEOM_Shape the pers_ref is the Entry in the OCAF document */
229 TCollection_ExtendedString MainIOR;
231 TDF_Tool::Label(aDoc->GetData(), aPersRefString, Lab );
233 Handle(TNaming_NamedShape) NS;
234 Lab.FindAttribute( TNaming_NamedShape::GetID(), NS );
235 TopoDS_Shape S = TNaming_Tool::GetShape(NS);
237 /* shapetype, index=0, topo, orb, shapetype, ismain=true and name are setted and modified later ? */
238 GEOM::GEOM_Shape_var result = CreateObject(S);
239 GEOMDS_Commands GC( aDoc->Main() ) ;
241 if ( GC.HasIOR(Lab) ) { /* shape already created/loaded */
245 /******************* Dependent object (not a main shape) *********************/
246 if( GC.IsDependentShape(Lab) ) {
248 TDF_Label mainLabel ;
249 Standard_Boolean mainShapeOk = GC.GetMainShapeLabel(Lab, mainLabel) ;
251 /* Main object not yet loaded we load/create it */
252 if( !GC.HasIOR(mainLabel) ) {
254 TCollection_AsciiString entry;
255 TDF_Tool::Entry(mainLabel,entry);
256 CORBA::String_var ent = strdup(entry.ToCString());
258 /* Create the main object recursively */
259 MainIOR = LocalPersistentIDToIOR(theSObject, ent, isMultiFile, isASCII) ;
261 GC.ReturnNameIOR( mainLabel, MainIOR );
264 result->MainName( TCollection_AsciiString(MainIOR).ToCString() ) ;
265 result->IsMainShape(false) ;
266 result->ShapeId(aPersRefString);
268 Handle(TDF_Reference) aRef;
269 Lab.FindAttribute( TDF_Reference::GetID(), aRef );
270 TDF_Label myL = aRef->Get() ;
271 Handle(TNaming_NamedShape) NN;
272 myL.FindAttribute( TNaming_NamedShape::GetID(), NN );
273 TopoDS_Shape mainTopo = TNaming_Tool::GetShape(NN);
275 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
277 if(S.ShapeType() != TopAbs_COMPOUND) {
278 /* to set the index of a unique sub shape (Explode All ONLY for the moment !) */
281 TopTools_MapOfShape M;
282 TopExp_Explorer Exp ;
283 for( Exp.Init(mainTopo, TopAbs_ShapeEnum( result->ShapeType() )) ; Exp.More(); Exp.Next() ) {
284 if ( M.Add(Exp.Current()) ) {
285 if(Exp.Current().IsSame(S) ) {
292 result->Index(ListOfID) ;
293 return result->Name();
296 /* Here is a TopAbs_COMPOUND : we set the list/index for a compound : containing two or more sub shapes */
297 /* Warning : the Corba shape has a shapetype Compound : in GEOMDS_Client we have to retrieve the kind of */
298 /* subshapes contained in this compound ! */
299 TopTools_SequenceOfShape SS;
301 TopExp_Explorer exp ;
302 TopAbs_ShapeEnum subType ;
304 /* Set all sub shapes in a sequence of shapes */
305 for ( it.Initialize( S, true, true ) ; it.More(); it.Next() ) {
306 subType = it.Value().ShapeType() ;
307 SS.Append( it.Value() ) ;
310 ListOfID->length( SS.Length() ) ;
311 int j, k ; /* in TopTools_SequenceOfShape index start at 1 */
313 for( k=1; k<=SS.Length(); k++ ) {
315 for( exp.Init( mainTopo, subType ); exp.More(); exp.Next() ) {
316 if( exp.Current().IsSame( SS.Value(k) ) ) {
322 result->Index(ListOfID) ;
323 return result->Name();
327 /******************* Independent object (not a sub shape) *********************/
329 result->IsMainShape(true) ;
330 if( !GC.AddIORNameAttribute(Lab, result->Name() ) ) {
331 MESSAGE("in LocalPersistentIDToIOR, NAME/IOR attribute already exist." << endl ) ;
333 Handle(TNaming_NamedShape) NamedShape ;
334 bool notTested = Lab.FindAttribute(TNaming_NamedShape::GetID(), NamedShape) ;
335 result->ShapeId(aPersRefString);
336 return result->Name();
340 //============================================================================
341 // function : CanPublishInStudy
343 //============================================================================
344 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
346 GEOM::GEOM_Shape_var aShape = GEOM::GEOM_Shape::_narrow(theIOR);
347 return !(aShape->_is_nil());
351 //============================================================================
352 // function : PublishInStudy
354 //============================================================================
355 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
356 SALOMEDS::SObject_ptr theSObject,
357 CORBA::Object_ptr theObject,
358 const char* theName) throw (SALOME::SALOME_Exception)
360 SALOMEDS::SObject_var aResultSO;
361 if(CORBA::is_nil(theObject)) return aResultSO;
363 GEOM::GEOM_Shape_var aShape = GEOM::GEOM_Shape::_narrow(theObject);
364 if(aShape->_is_nil()) return aResultSO;
366 if(theStudy->_is_nil()) return aResultSO;
368 SALOMEDS::GenericAttribute_var anAttr;
369 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
371 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
372 if (aFather->_is_nil()) {
373 aFather = aStudyBuilder->NewComponent("GEOM");
374 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
375 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
376 aName->SetValue("Geometry");
377 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
378 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
379 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
381 if (aFather->_is_nil()) return aResultSO;
383 if (CORBA::is_nil(theSObject)) {
384 aResultSO = aStudyBuilder->NewObject(aFather);
386 if (!theSObject->ReferencedObject(aResultSO))
387 THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
389 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
390 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
391 anIOR->SetValue(aShape->Name());
393 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
394 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
395 TCollection_AsciiString aShapeName("Shape_");
397 if ( aShape->ShapeType() == GEOM::COMPOUND ) {
398 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
399 aShapeName = "Compound_";
400 } else if ( aShape->ShapeType() == GEOM::COMPSOLID ) {
401 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
402 aShapeName = "Compsolid_";
403 } else if ( aShape->ShapeType() == GEOM::SOLID ) {
404 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
405 aShapeName = "Solid_";
406 } else if ( aShape->ShapeType() == GEOM::SHELL ) {
407 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
408 aShapeName = "Shell_";
409 } else if ( aShape->ShapeType() == GEOM::FACE ) {
410 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
411 aShapeName = "Face_";
412 } else if ( aShape->ShapeType() == GEOM::WIRE ) {
413 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
414 aShapeName = "Wire_";
415 } else if ( aShape->ShapeType() == GEOM::EDGE ) {
416 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
417 aShapeName = "Edge_";
418 } else if ( aShape->ShapeType() == GEOM::VERTEX ) {
419 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
420 aShapeName = "Vertex_";
422 if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
423 else aShapeName = TCollection_AsciiString(strdup(theName));
425 //Set a name of the added shape
426 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
427 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
428 aNameAttrib->SetValue(aShapeName.ToCString());
430 //Add a reference to published object
431 // aStudyBuilder->Addreference(theObject, aResultSO);
432 return aResultSO._retn();
436 //============================================================================
438 // purpose : save OCAF/Geom document
439 //============================================================================
440 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
443 SALOMEDS::TMPFile_var aStreamFile;
444 // Get a temporary directory to store a file
445 TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
446 // Create a list to store names of created files
447 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
449 // Prepare a file name to open
450 TCollection_AsciiString aNameWithExt(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
451 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
452 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
453 // Build a full file name of temporary file
454 TCollection_AsciiString aFullName = aTmpDir + aNameWithExt;
455 // Save GEOM component in this file
456 myOCAFApp->SaveAs(myCurrentOCAFDoc, aFullName);
457 // Conver a file to the byte stream
458 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
459 // Remove the created file and tmp directory
460 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
461 // Return the created byte stream
462 return aStreamFile._retn();
465 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
468 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
469 return aStreamFile._retn();
473 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
474 const SALOMEDS::TMPFile& theStream,
478 if (theStream.length() <= 9) {
479 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
483 // Get a temporary directory for a file
484 TCollection_AsciiString aTmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
485 // Conver the byte stream theStream to a file and place it in tmp directory
486 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
490 // Prepare a file name to open
491 TCollection_AsciiString aNameWithExt(aSeq[0]);
492 TCollection_AsciiString aFullName = aTmpDir + aNameWithExt;
495 if (myOCAFApp->Open(aFullName, myCurrentOCAFDoc) != CDF_RS_OK) return false;
497 // Remove the created file and tmp directory
498 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
500 SALOMEDS::Study_var Study = theComponent->GetStudy();
501 TCollection_AsciiString name( strdup(Study->Name()) );
503 int StudyID = Study->StudyId();
504 myStudyIDToDoc.Bind( StudyID, myCurrentOCAFDoc );
507 /* We clear all IOR (nameIOR) attributes of all objects before reconstruction */
508 /* This information will be setted when each object is reconstructed */
509 GEOMDS_Commands GC( myCurrentOCAFDoc->Main() ) ;
510 GC.ClearAllIOR(myCurrentOCAFDoc->Main());
515 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
516 const SALOMEDS::TMPFile& theStream,
519 return Load(theComponent, theStream, theURL, isMultiFile);
522 // //============================================================================
523 // // function : Save()
524 // // purpose : save OCAF/Geom document
525 // //============================================================================
526 // void GEOM_Gen_i::Save(const char *IORSComponent, const char *aUrlOfFile)
529 // TCollection_ExtendedString path(strdup(aUrlOfFile));
530 // TCollection_ExtendedString pathWithExt = path + TCollection_ExtendedString(".sgd");
531 // myOCAFApp->SaveAs(myCurrentOCAFDoc,pathWithExt);
535 // //============================================================================
536 // // function : Load()
537 // // purpose : Load OCAF/Geom document
538 // //============================================================================
539 // void GEOM_Gen_i::Load(const char *IORSComponent, const char *aUrlOfFile)
542 // TCollection_ExtendedString path(strdup(aUrlOfFile));
543 // TCollection_ExtendedString pathWithExt = path + TCollection_ExtendedString(".sgd");
545 // myOCAFApp->Open(pathWithExt,myCurrentOCAFDoc);
547 // SALOMEDS::SComponent_var SC = SALOMEDS::SComponent::_narrow(_orb->string_to_object(IORSComponent));
548 // SALOMEDS::Study_var Study = SC->GetStudy();
549 // TCollection_AsciiString name( strdup(Study->Name()) );
551 // int StudyID = Study->StudyId();
552 // myStudyIDToDoc.Bind( StudyID, myCurrentOCAFDoc );
553 // myStudyID = StudyID;
555 // /* We clear all IOR (nameIOR) attributes of all objects before reconstruction */
556 // /* This information will be setted when each object is reconstructed */
557 // GEOMDS_Commands GC( myCurrentOCAFDoc->Main() ) ;
558 // GC.ClearAllIOR(myCurrentOCAFDoc->Main());
564 //============================================================================
565 // function : Close()
567 //============================================================================
568 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
570 int anID = theComponent->GetStudy()->StudyId();
571 if (anID == myStudyID) GetCurrentStudy(0); // set default value of current study ID, if current is deleted
572 if (myStudyIDToDoc.IsBound(anID)) {
573 // close document in the application
574 // Handle(TDocStd_Owner) anOwner;
575 Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(myStudyIDToDoc.Find(anID));
576 // Handle(TDocStd_Document) anEmptyDoc;
577 // if (aDoc->Main().Root().FindAttribute(TDocStd_Owner::GetID(), anOwner)) {
578 // anOwner->SetDocument(anEmptyDoc);
579 // cout<<"********** Nullify owner of document"<<endl;
581 myOCAFApp->Close(aDoc);
582 myStudyIDToDoc.UnBind(anID); // remove document from GEOM documents data map
586 //============================================================================
587 // function : CanCopy()
589 //============================================================================
590 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
591 // Try to retrieve known by Geometry component GEOM_shape by given IOR
592 SALOMEDS::GenericAttribute_var anAttr;
593 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
594 GEOM::GEOM_Shape_var aShape = GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
595 // If the object is null one it can't be copied: return false
596 if (aShape->_is_nil()) return false;
600 //============================================================================
601 // function : CopyFrom()
603 //============================================================================
604 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
605 // Declare a sequence of the byte to store the copied object
606 SALOMEDS::TMPFile_var aStreamFile;
608 // Try to get GEOM_Shape object by given SObject
609 SALOMEDS::GenericAttribute_var anAttr;
610 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
611 GEOM::GEOM_Shape_var aShape = GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
612 // If the object is null one it can't be copied: return false
613 if (aShape->_is_nil()) return aStreamFile._retn();
615 GetCurrentStudy(theObject->GetStudy()->StudyId());
617 // Convert a TopoDS_Shape to a stream of bytes
618 TopoDS_Shape aTopology = GetTopoShape(aShape);
619 if (aTopology.IsNull()) return aStreamFile._retn();
620 ostrstream aStreamedShape;
621 BRepTools::Write(aTopology, aStreamedShape);
622 int aSize = aStreamedShape.pcount();
623 char* aBuffer = new char[aSize];
624 memcpy(aBuffer, aStreamedShape.str(), aSize);
625 aStreamedShape.rdbuf()->freeze(0);
627 aStreamFile = new SALOMEDS::TMPFile(aSize, aSize, (CORBA::Octet*)aBuffer, 1);
629 // Assign an ID = 1 the the type GEOM_Shape
632 // Return created TMPFile
633 return aStreamFile._retn();
636 //============================================================================
637 // function : CanPaste()
639 //============================================================================
640 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
641 // The Geometry component can paste only objects copied by Geometry component
642 // and with the object type = 1
643 // cout<<"********** GEOM_Gen_i::CanPaste ("<<theComponentName<<","<<theObjectID<<")"<<endl;
644 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
648 //============================================================================
649 // function : PasteInto()
651 //============================================================================
652 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
653 CORBA::Long theObjectID,
654 SALOMEDS::SObject_ptr theObject) {
655 // Find the current Study and StudyBuilder
656 SALOMEDS::Study_var aStudy = theObject->GetStudy();
657 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
659 // Retrieve a TopoDS_Shape from byte stream
660 TopoDS_Shape aTopology;
661 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
662 BRep_Builder aBuilder;
664 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
665 } catch (Standard_Failure) {
666 // cout<<"GEOM_Gen_i::PasteInto exception"<<endl;
670 // Create new object in Geometry component using retrieved topology
671 GEOM::GEOM_Shape_var aShape = CreateObject(aTopology);
672 GetCurrentStudy(aStudy->StudyId());
673 const char *anEntry = InsertInLabel(aTopology, aShape->Name(), myCurrentOCAFDoc) ;
674 aShape->ShapeId(anEntry) ;
676 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
677 SALOMEDS::SObject_var aNewSO;
678 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
679 aNewSO = aStudyBuilder->NewObject(theObject);
680 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
681 // Add IORAttribute to the Study and set IOR of the created GEOM_Shape to it
682 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
683 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
684 anIOR->SetValue(aShape->Name());
686 // Return the created in the Study SObject
687 return aNewSO._retn();
690 //============================================================================
691 // function : ComponentDataType()
693 //============================================================================
694 char* GEOM_Gen_i::ComponentDataType()
696 return strdup("GEOM");
699 //============================================================================
700 // function : register()
701 // purpose : register 'name' in 'name_service'
702 //============================================================================
703 void GEOM_Gen_i::register_name(char * name)
705 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(POA_GEOM::GEOM_Gen::_this());
706 name_service->Register(g, strdup(name));
711 //================================================================================
712 // function : SequenceOfShapeFromListOfGeomShape()
713 // purpose : Define a sequence of shapes from 'listShapes' and return its length.
714 // : No control is made on shapes !
715 //================================================================================
716 int GEOM_Gen_i::SequenceOfShapeFromListOfGeomShape( const GEOM::GEOM_Gen::ListOfGeomShapes& listShapes,
717 TopTools_SequenceOfShape& SS )
719 int nbShapes = listShapes.length() ;
723 for(int i=0; i<nbShapes; i++) {
724 GEOM::GEOM_Shape_var aGeomShape = listShapes[i] ;
725 TopoDS_Shape aShape = GetTopoShape(aGeomShape) ;
734 //=================================================================================
735 // function : GetTopoShape()
736 // purpose : Returns a TopoDS_Shape from a GEOM::GEOM_Shape_ptr in 'myCurrentOCAFDoc'
737 // : A null shape is returned if not possible
738 //=================================================================================
739 TopoDS_Shape GEOM_Gen_i::GetTopoShape(GEOM::GEOM_Shape_ptr shape_ptr)
744 Handle(TDF_Data) D = myCurrentOCAFDoc->GetData() ;
745 TDF_Tool::Label( D, strdup(shape_ptr->ShapeId()), lab, true ) ;
746 Handle(TNaming_NamedShape) NamedShape ;
747 bool res = lab.FindAttribute(TNaming_NamedShape::GetID(), NamedShape) ;
750 return tds ; /* a null shape is returned */
753 return TNaming_Tool::GetShape(NamedShape) ;
759 //=================================================================================
760 // function : GetStringFromIOR()
761 // purpose : returns a string that represents a 'GEOM::GEOM_Shape_var'
762 //=================================================================================
763 const char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Shape_var shapeIOR) {
764 const char * ret = _orb->object_to_string(shapeIOR) ;
770 //=================================================================================
771 // function : GetIORFromString()
772 // purpose : returns a 'GEOM::GEOM_Shape_var' from a string representing it
773 //=================================================================================
774 GEOM::GEOM_Shape_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
775 GEOM::GEOM_Shape_var shapeIOR;
776 if(strcmp(stringIOR,"") != 0){
777 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
778 if(!CORBA::is_nil(anObject))
779 shapeIOR = GEOM::GEOM_Shape::_narrow(anObject.in()) ;
781 return shapeIOR._retn() ;
786 //==================================================================================
787 // function : InsertInLabel()
788 // purpose : Insert S = Shape and mystr = name in a new Label of Geom/OCAF document
789 // : and returns the corresponding OCAF entry
790 //==================================================================================
791 const char * GEOM_Gen_i::InsertInLabel(TopoDS_Shape S, const char *mystr, Handle(TDocStd_Document) OCAFDoc)
793 GEOMDS_Commands GC(OCAFDoc->Main());
794 /* add attributs S and mystr in a new label */
795 TDF_Label Lab = GC.AddShape (S, strdup(mystr));
797 TCollection_AsciiString entry;
798 TDF_Tool::Entry(Lab,entry);
799 const char *ent = entry.ToCString() ;
804 //==================================================================================
805 // function : InsertInLabelDependentShape()
806 // purpose : Insert S = Shape and its nameIor in a new Label of Geom/OCAF document
807 // : insert also a reference attribute (a label) to the main shape 'mainshap_ptr'.
808 // : and returns the corresponding OCAF entry of the new label.
809 //==================================================================================
810 const char * GEOM_Gen_i::InsertInLabelDependentShape( TopoDS_Shape S,
812 GEOM::GEOM_Shape_ptr mainshape_ptr,
813 Handle(TDocStd_Document) OCAFDoc )
815 GEOMDS_Commands GC(OCAFDoc->Main());
816 /* add attributs S and nameIor in a new label */
818 /* retrieve the label of the main shape in the document */
819 TDF_Label mainRefLab;
820 TDF_Tool::Label(OCAFDoc->GetData(), mainshape_ptr->ShapeId(), mainRefLab);
822 /* add attributs : S, nameIor and ref to main */
823 TDF_Label Lab = GC.AddDependentShape(S, strdup(nameIor), mainRefLab);
825 TCollection_AsciiString entry;
826 TDF_Tool::Entry(Lab, entry);
827 const char *ent = entry.ToCString() ;
832 //=================================================================================
833 // function : InsertInLabelOneArgument()
835 //=================================================================================
836 void GEOM_Gen_i::InsertInLabelOneArgument(TopoDS_Shape main_topo,
837 GEOM::GEOM_Shape_ptr shape_ptr,
838 TopoDS_Shape result_topo,
839 GEOM::GEOM_Shape_ptr result,
840 Handle(TDocStd_Document) OCAFDoc)
842 /* Put shape and name into geom/OCAF doc */
843 GEOMDS_Commands GC(OCAFDoc->Main());
844 /* Add attributs 'shape' and 'name_ior' in a new label */
845 TDF_Label Lab = GC.Generated( main_topo, result_topo, result->Name() );
846 TCollection_AsciiString entry;
847 TDF_Tool::Entry(Lab, entry);
848 result->ShapeId( entry.ToCString() ) ;
850 /* Create a new label */
851 TDF_Label NewLab = Lab.NewChild();
852 TCollection_ExtendedString Value("Arguments");
853 TDataStd_Name::Set(NewLab,Value);
855 TDF_Label NewLab1 = NewLab.NewChild();
857 TDF_Tool::Label(OCAFDoc->GetData(), shape_ptr->ShapeId(), RefLab);
858 TDF_Reference::Set(NewLab1, RefLab);
862 //=================================================================================
863 // function : InsertInLabelMoreArguments()
865 //=================================================================================
866 void GEOM_Gen_i::InsertInLabelMoreArguments(TopoDS_Shape main_topo,
867 GEOM::GEOM_Shape_ptr result,
868 const GEOM::GEOM_Gen::ListOfIOR& ListShapes,
869 Handle(TDocStd_Document) OCAFDoc)
871 /* Put shape and name into geom/OCAF doc */
872 GEOMDS_Commands GC(OCAFDoc->Main());
873 /* Add attributs TopoDS and name_ior in a new label */
874 TDF_Label Lab = GC.AddShape(main_topo, result->Name() );
875 TCollection_AsciiString entry;
876 TDF_Tool::Entry(Lab, entry);
878 /* Create a new label */
879 TDF_Label NewLab = Lab.NewChild();
880 TCollection_ExtendedString Value("Arguments");
881 TDataStd_Name::Set(NewLab, Value);
883 for (unsigned int ind = 0; ind < ListShapes.length(); ind++) {
885 TDF_Label NewLab1 = NewLab.NewChild();
886 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[ind] );
889 TDF_Tool::Label(OCAFDoc->GetData(), aShape->ShapeId(), RefLab);
890 TDF_Reference::Set(NewLab1, RefLab);
892 result->ShapeId(entry.ToCString());
897 //=================================================================================
898 // function: NbLabels()
900 //=================================================================================
901 CORBA::Short GEOM_Gen_i::NbLabels()
903 return TDF_Tool::NbLabels( myCurrentOCAFDoc->Main() );
908 //=================================================================================
909 // function: GetCurrentStudy()
910 // purpose : Finds or creates the geom/OCAF document corresponding to the index
912 //=================================================================================
913 void GEOM_Gen_i::GetCurrentStudy(CORBA::Long StudyID)
915 /* If StudyID is known we link myCurrentOCAFDoc to it */
916 if (myStudyIDToDoc.IsBound(StudyID)) {
917 myCurrentOCAFDoc = Handle(TDocStd_Document)::DownCast(myStudyIDToDoc(StudyID));
919 /* Create a new OCAFDoc and link it to 'StudyID' argument */
921 myOCAFApp->NewDocument("SALOME_GEOM",myCurrentOCAFDoc);
922 myStudyIDToDoc.Bind(StudyID,myCurrentOCAFDoc);
928 //================================================================================
929 // function : CreateObject()
930 // purpose : private function to create a complete CORBA object and return it
931 //================================================================================
932 GEOM::GEOM_Shape_ptr GEOM_Gen_i::CreateObject(TopoDS_Shape& tds)
934 // if ( tds.ShapeType() == TopAbs_COMPOUND ) {
935 // TopoDS_Iterator itr(tds);
938 // while (itr.More()) {
940 // res = itr.Value();
948 GEOM::shape_type st = GEOM::shape_type(tds.ShapeType()) ; /* casting */
950 /* Create the CORBA servant holding the TopoDS_Shape */
951 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
952 GEOM::GEOM_Shape::ListOfSubShapeID_var index = new GEOM::GEOM_Shape::ListOfSubShapeID;
954 GEOM_Shape_i * shape_servant = new GEOM_Shape_i(tds, _orb, engine, index, st, true);
955 GEOM::GEOM_Shape_var shape = GEOM::GEOM_Shape::_narrow(shape_servant->_this());
957 /* Create and set the name (IOR of shape converted into a string) */
958 string name_ior = _orb->object_to_string(shape) ;
959 shape->Name( name_ior.c_str() );
960 shape->NameType( "" );
964 //=======================================================================
965 //function : CreateSubObject
967 //=======================================================================
969 GEOM::GEOM_Shape_ptr GEOM_Gen_i::CreateSubObject(const TopoDS_Shape& SubShape,
970 const GEOM::GEOM_Shape_ptr MainShape,
971 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID)
973 GEOM::shape_type st = GEOM::shape_type(SubShape.ShapeType()) ; /* casting */
975 /* Create the CORBA servant holding the TopoDS_Shape */
976 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
977 GEOM_Shape_i * shape_servant =
978 new GEOM_Shape_i(SubShape, _orb, engine, ListOfID, st, false);
979 GEOM::GEOM_Shape_var shape = GEOM::GEOM_Shape::_narrow(shape_servant->_this());
981 /* Create and set the name (IOR of shape converted into a string) */
982 string name_ior = _orb->object_to_string(shape) ;
983 shape->Name( name_ior.c_str() );
984 /* create and set the mainname (IOR of shape converted into a string) */
985 const char *mainname_ior = _orb->object_to_string(MainShape) ;
986 shape->MainName(mainname_ior);
987 /* precaution : NameType will be set precisely in GUI */
988 shape->NameType( "" );
989 /* add 'SubShape' its 'nameIOR' and a reference to the main shape thanks to method below */
991 InsertInLabelDependentShape(SubShape, shape->Name(), MainShape, myCurrentOCAFDoc) ;
992 shape->ShapeId( entry ) ;
997 //=======================================================================
998 // function : SuppressFacesGlue()
999 // purpose : Define a compound of shells after suppress of mapFaces in the
1000 // : shape S and return the number of shells of the compound.
1001 //=======================================================================
1002 int GEOM_Gen_i::SuppressFacesGlue( const TopoDS_Shape& S,
1003 const TopTools_MapOfShape& mapFaces,
1004 TopoDS_Shape& aCompoundOfShells )
1005 throw (SALOME::SALOME_Exception)
1007 BRepTools_Quilt Glue;
1008 aCompoundOfShells.Nullify() ;
1010 for ( TopExp_Explorer exp( S, TopAbs_FACE); exp.More(); exp.Next() ) {
1011 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1012 if ( !mapFaces.Contains(F) ) {
1013 /* this face must not to be suppressed */
1018 /* Use specif method to calculate the compound of shells */
1019 aCompoundOfShells = Glue.Shells();
1021 if( aCompoundOfShells.ShapeType() != TopAbs_COMPOUND ) {
1022 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SuppressFacesGlue() : not a GEOM::COMPOUND", SALOME::BAD_PARAM);
1025 /* explore Compound for verification and return the number of shells */
1026 int numberOfShell = 0 ;
1027 for ( TopExp_Explorer exp1( aCompoundOfShells, TopAbs_SHELL); exp1.More(); exp1.Next() )
1030 return numberOfShell ;
1034 //=====================================================================================
1035 // function : GetIndexTopology()
1036 // purpose : return the index of a sub shape in a shape (index starts at 1)
1037 // : Return -1 if not found
1038 //=====================================================================================
1039 int GEOM_Gen_i::GetIndexTopology(const TopoDS_Shape& subshape, const TopoDS_Shape& mainShape)
1041 if( mainShape.IsNull() || subshape.IsNull() )
1045 if (subshape.ShapeType() == TopAbs_COMPOUND)
1048 TopTools_ListOfShape CL;
1049 CL.Append( mainShape );
1050 TopTools_ListIteratorOfListOfShape itC;
1051 for (itC.Initialize( CL ); itC.More(); itC.Next())
1053 for (it.Initialize( itC.Value() ); it.More(); it.Next())
1055 if ( it.Value().ShapeType() == TopAbs_COMPOUND)
1057 if (it.Value().IsSame(subshape))
1061 CL.Append( it.Value() );
1068 TopExp_Explorer Exp ( mainShape, subshape.ShapeType() );
1069 TopTools_MapOfShape M;
1070 while ( Exp.More() )
1072 if ( M.Add(Exp.Current()) )
1074 if ( Exp.Current().IsSame(subshape) )
1085 //================================================================================
1086 // function : IndexOfFacesOfSubShell()
1087 // purpose : Return a list of indices corresponding to the faces of a 'subShell'
1088 // : in the main shape 'S'
1089 //================================================================================
1090 GEOM::GEOM_Shape::ListOfSubShapeID* GEOM_Gen_i::IndexOfFacesOfSubShell( const TopoDS_Shape& S,
1091 const TopoDS_Shape subShell )
1092 throw (SALOME::SALOME_Exception)
1095 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
1096 ListOfID->length(0) ;
1097 if( subShell.IsNull() || subShell.ShapeType() != TopAbs_SHELL ) {
1098 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::IndexOfFacesOfSubShell() : null shape or not a GEOM::SHELL", SALOME::BAD_PARAM);
1101 /* put faces of subShell in a Map of faces */
1103 TopTools_MapOfShape mapFaces ;
1104 for( TopExp_Explorer Exp1( subShell, TopAbs_FACE ); Exp1.More(); Exp1.Next() ) {
1105 mapFaces.Add(Exp1.Current() ) ;
1110 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::IndexOfFacesOfSubShell() : no faces in sub shell", SALOME::BAD_PARAM);
1112 /* Find index of each face of subshell in the main topology and put its index in ListOfID */
1114 for ( TopExp_Explorer Exp2(S, TopAbs_FACE); Exp2.More(); Exp2.Next() ) {
1116 const TopoDS_Face& F = TopoDS::Face( Exp2.Current() ) ;
1118 if( mapFaces.Contains(F) ) {
1119 int n = GetIndexTopology( F, S ) ;
1121 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::IndexOfFacesOfSubShell() : no index found", SALOME::BAD_PARAM);
1124 ListOfID->length(size) ;
1125 ListOfID[size-1] = n ;
1129 return ListOfID._retn() ;
1134 //================================================================================
1135 // function : ListOfIDIntoMapOfShapes()
1136 // purpose : Define a MapOfShapes from a main topology 'S' a 'subShapeType'
1137 // : and a list of indices 'L'.
1138 // : Return true if 'aMap' is not empty
1139 //================================================================================
1140 bool GEOM_Gen_i::ListOfIDIntoMapOfShapes( const TopoDS_Shape& S,
1141 const GEOM::GEOM_Shape::ListOfSubShapeID& L,
1142 const int subShapeType,
1143 TopTools_MapOfShape& aMap )
1145 if( L.length() < 1 || S.IsNull() ) {
1150 for( int k=0; k<L.length(); k++ ) {
1151 /* indices start at 1 in list L */
1153 TopExp_Explorer exp ;
1154 TopTools_MapOfShape M;
1155 for( exp.Init( S, TopAbs_ShapeEnum(subShapeType) ); exp.More(); exp.Next() ) {
1156 if ( M.Add(exp.Current()) )
1159 aMap.Add( exp.Current() ) ;
1170 //================================================================================
1171 // function : ListOfIDIntoSequenceOfShapes()
1172 // purpose : Define 'aSequenceOfShapes' from a main topology 'S' a 'subShapeType'
1173 // : and a list of indices 'L'.
1174 // : Return true if 'aSequenceOfShapes' is not empty
1175 //================================================================================
1176 bool GEOM_Gen_i::ListOfIDIntoSequenceOfShapes( const TopoDS_Shape& S,
1177 const GEOM::GEOM_Shape::ListOfSubShapeID& L,
1178 const int subShapeType,
1179 TopTools_SequenceOfShape& aSequenceOfShapes )
1181 if( L.length() < 1 || S.IsNull() ) {
1185 aSequenceOfShapes.Clear() ;
1186 for( int k=0; k<L.length(); k++ ) {
1187 /* indices start at 1 in list L */
1189 TopExp_Explorer exp ;
1190 for( exp.Init( S, TopAbs_ShapeEnum(subShapeType) ); exp.More(); exp.Next() ) {
1192 aSequenceOfShapes.Append( exp.Current() ) ;
1202 //================================================================================
1203 // function : SuppressFaces()
1204 // purpose : Suppress faces contained in ListOfID from 'shape'.
1205 // : Return a list of Geom shapes each one is a main shape GEOM::FACE or GEOM::SHELL
1206 //================================================================================
1207 GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SuppressFaces( GEOM::GEOM_Shape_ptr shape,
1208 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID )
1209 throw (SALOME::SALOME_Exception)
1211 GEOM::GEOM_Gen::ListOfGeomShapes_var listOfGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
1212 listOfGeomShapes->length(0) ;
1214 TopoDS_Shape mainShape = GetTopoShape(shape);
1215 if( mainShape.IsNull() )
1216 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SuppressFaces() : null argument shape", SALOME::BAD_PARAM);
1218 if( ListOfID.length() < 1 )
1219 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SuppressFaces() : empty ListOfID", SALOME::BAD_PARAM);
1221 /* Define 'mapFaces' a map of faces to be suppressed in mainShape */
1222 TopTools_MapOfShape mapFaces ;
1223 if( !ListOfIDIntoMapOfShapes(mainShape, ListOfID, TopAbs_FACE, mapFaces ) ) {
1224 return listOfGeomShapes._retn();
1227 /* Call algorithm to calculate a compound of shells resulting of face suppression */
1228 int numberOfShells = 0 ;
1229 TopoDS_Shape aCompoundOfShells ;
1230 numberOfShells = SuppressFacesGlue(mainShape, mapFaces, aCompoundOfShells) ;
1231 if(numberOfShells < 1) {
1232 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::Suppressfaces() : no shells", SALOME::BAD_PARAM);
1235 /* Create a shell for each shell contained in 'aCompoundOfShells' and */
1236 /* put it in the list of GeomShapes to be returned. */
1237 /* But if the shell is composed of only a face we create a face and not a shell */
1239 for( TopExp_Explorer exp(aCompoundOfShells, TopAbs_SHELL); exp.More(); exp.Next() ) {
1241 const TopoDS_Shell& aShell = TopoDS::Shell( exp.Current() );
1242 if( aShell.IsNull() ) {
1243 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::Suppressfaces() : null shell", SALOME::BAD_PARAM);
1246 GEOM::GEOM_Shape::ListOfSubShapeID_var aList = new GEOM::GEOM_Shape::ListOfSubShapeID;
1247 aList = IndexOfFacesOfSubShell(mainShape, aShell) ;
1249 if( aList->length() < 1 ) {
1250 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SuppressFaces() : aList is empty", SALOME::BAD_PARAM);
1253 TopoDS_Shape aShellOrFace ;
1254 /* Only a face into the shell : we create a single face instead of a shell : 'aList' is unchanged */
1255 if( aList->length() == 1 ) {
1256 TopExp_Explorer exp ;
1257 exp.Init( aShell, TopAbs_FACE ) ;
1259 aShellOrFace = exp.Current() ;
1262 aShellOrFace = aShell ;
1265 /* Create CORBA object */
1266 GEOM::GEOM_Shape_var result = CreateObject(aShellOrFace) ;
1267 if( CORBA::is_nil(result) ) {
1268 THROW_SALOME_CORBA_EXCEPTION("Suppress Faces aborted : null result", SALOME::BAD_PARAM);
1271 InsertInLabelOneArgument(mainShape, shape, aShellOrFace, result, myCurrentOCAFDoc) ;
1273 listOfGeomShapes->length(i) ;
1274 listOfGeomShapes[i-1] = result ;
1277 return listOfGeomShapes._retn() ;
1282 //================================================================================
1283 // function : IsShapeInSequence()
1284 // purpose : return true is aShape is in SS. The test method is 'IsSame()'
1285 //================================================================================
1286 bool GEOM_Gen_i::IsShapeInSequence(const TopTools_SequenceOfShape& SS, const TopoDS_Shape& aShape)
1288 if( aShape.IsNull() || SS.IsEmpty() )
1290 for( int i=1; i<=SS.Length(); i++) {
1291 if( SS.Value(i).IsSame(aShape) )
1298 //================================================================================
1299 // function : FreeEdgesFromMapOfFace()
1300 // purpose : Define MS a map of all edges of faces of 'MSfaces'
1301 // : All multiple edges are removed !
1302 //================================================================================
1303 void GEOM_Gen_i::FreeEdgesFromMapOfFace( const TopTools_MapOfShape& MSfaces,
1304 TopTools_MapOfShape& MS )
1307 TopTools_MapOfShape Multiple ;
1308 TopTools_MapIteratorOfMapOfShape it ;
1309 for( it.Initialize(MSfaces); it.More(); it.Next() ) {
1310 TopoDS_Shape aFace = it.Key() ;
1311 TopExp_Explorer exp ;
1312 for( exp.Init( aFace, TopAbs_EDGE); exp.More(); exp.Next() ) {
1313 if( !Multiple.Contains( exp.Current() ) && !MS.Add( exp.Current() ) ) {
1314 MS.Remove( exp.Current() ) ;
1315 Multiple.Add( exp.Current() ) ;
1323 //================================================================================
1324 // function : MapRemoveSequence()
1325 // purpose : In term of shapes ST = MS - SSRemove
1327 //================================================================================
1328 void GEOM_Gen_i::MapRemoveSequence( const TopTools_MapOfShape& MS,
1329 const TopTools_SequenceOfShape& SSRemove,
1330 TopTools_SequenceOfShape& ST )
1333 TopTools_MapIteratorOfMapOfShape it ;
1334 for( it.Initialize(MS); it.More(); it.Next() ) {
1335 TopoDS_Shape aShape = it.Key() ;
1336 if( !IsShapeInSequence( SSRemove, aShape ) )
1337 ST.Append( aShape ) ;
1344 //================================================================================
1345 // function : SuppressHoleSubRoutine()
1346 // purpose : Define recursively 'MSfacesSuppress' a list of faces to suppress in a hole
1347 //================================================================================
1348 void GEOM_Gen_i::SuppressHoleSubRoutine( const TopoDS_Shape& mainShape,
1349 const TopoDS_Face& aFace,
1350 const TopTools_SequenceOfShape& SSedgesOfWire,
1351 const TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgesFaces,
1352 const TopTools_MapOfShape& MSfaces,
1353 TopTools_MapOfShape& MSfacesSuppress,
1354 const Standard_Boolean withEndFace,
1355 const TopoDS_Face& endFace,
1356 TopTools_MapOfShape& MSwireEndEdges )
1357 throw (SALOME::SALOME_Exception)
1359 TopTools_MapOfShape MS ;
1360 TopTools_SequenceOfShape SU ;
1361 FreeEdgesFromMapOfFace(MSfaces, MS) ; /* MS = free edges of MSfaces */
1362 MapRemoveSequence(MS, SSedgesOfWire, SU) ; /* SU = MS - SSedgesOfWire */
1364 if( SU.IsEmpty() ) {
1368 /* Here SU contains new edges to find new faces to suppress */
1369 /* Define the list of faces of SU edges that aren't in faces of MSfacesSuppress in order to add into */
1370 /* For each edge we have a map of all its faces : it's in 'aMapEdgesFaces' */
1371 TopTools_MapOfShape MSfacesTmp ;
1372 for( int v=1; v<=SU.Length(); v++ ) {
1373 TopoDS_Shape E = SU.Value(v) ;
1375 TopTools_ListOfShape LF ;
1376 int ind = aMapEdgesFaces.FindIndex(E) ;
1378 /* LF is the list of faces for an edge of SU : may be empty no matter */
1379 LF = aMapEdgesFaces.FindFromIndex(ind) ;
1381 TopTools_ListIteratorOfListOfShape it ;
1382 for( it.Initialize(LF); it.More(); it.Next() ) {
1384 if( withEndFace == false ) {
1385 if( F.IsSame(aFace) )
1386 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHoleSubRoutine() : hole traversing or ?", SALOME::BAD_PARAM);
1387 if( !MSfacesSuppress.Contains(F) ) {
1388 MSfacesSuppress.Add(F) ;
1389 MSfacesTmp.Add(F) ; // Dont remove the 'if' !
1392 else { /* withEndFace == true */
1393 if( F.IsSame(aFace) && !F.IsSame(endFace) )
1394 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHoleSubRoutine() : hole traversing incoherent ?", SALOME::BAD_PARAM);
1396 if( F.IsSame(endFace) ) {
1397 /* We have reached endFace if selection was correct so we add */
1398 /* edge in a map to find later the corresponding endWire (hole */
1399 MSwireEndEdges.Add(E) ;
1402 if( !MSfacesSuppress.Contains(F) ) {
1403 MSfacesSuppress.Add(F) ;
1410 /* Call recursively this routine */
1411 SuppressHoleSubRoutine( mainShape, aFace, SSedgesOfWire, aMapEdgesFaces, MSfacesTmp, MSfacesSuppress, withEndFace, endFace, MSwireEndEdges ) ;
1416 //================================================================================
1417 // function : GetShapeFromIndex()
1418 // purpose : Find 'tds' a sub shape of 'aShape' according to 'aList' that contains
1419 // : a unique index !
1420 // : Warning : index must be setted with the same exploration logic !
1421 // : So 'index' is calculated with no shape doublons !
1422 //================================================================================
1423 bool GEOM_Gen_i::GetShapeFromIndex( const TopoDS_Shape& aShape,
1424 const TopAbs_ShapeEnum aType,
1429 if (aShape.IsNull() || index < 1)
1431 /* Indices start at 1 */
1433 bool found = false ;
1434 TopExp_Explorer exp ;
1435 TopTools_MapOfShape M;
1436 for( exp.Init( aShape, aType ); exp.More(); exp.Next() ) {
1437 if( M.Add(exp.Current()) ) { /* if not a doublon : we compare */
1439 tds = exp.Current() ;
1450 //================================================================================
1451 // function : SuppressHolesInFaceOrShell() Main method.
1452 // purpose : Suppress holes identified by wires in a single face or shell
1454 //================================================================================
1455 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHolesInFaceOrShell( GEOM::GEOM_Shape_ptr shapeFaceShell,
1456 const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdWires )
1457 throw (SALOME::SALOME_Exception)
1459 GEOM::GEOM_Shape_var result;
1461 if( ListIdWires.length() < 1 )
1462 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace : no holes selected", SALOME::BAD_PARAM);
1464 const TopoDS_Shape tds = GetTopoShape(shapeFaceShell) ;
1465 if( tds.IsNull() || !IsValid(tds) )
1466 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace() : non valid main argument", SALOME::BAD_PARAM);
1468 /* Create a map of wires/holes to suppress */
1469 TopTools_MapOfShape MapHoles ;
1470 for ( int i = 0; i < ListIdWires.length(); i++ ) {
1472 if( !GetShapeFromIndex( tds, TopAbs_WIRE, ListIdWires[i], W ) )
1473 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace() : bad index ?", SALOME::BAD_PARAM);
1477 /* Test if argument is a face or shell */
1479 if( tds.ShapeType() == TopAbs_FACE )
1481 else if ( tds.ShapeType() == TopAbs_SHELL )
1484 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace() : not a face or a shell", SALOME::BAD_PARAM);
1486 /* Define two maps : all faces and faces to that will be modified */
1487 TopTools_MapOfShape MapFacesToModify ;
1488 TopTools_MapOfShape MapFacesAll ;
1489 TopExp_Explorer expF ;
1490 for( expF.Init( tds, TopAbs_FACE); expF.More(); expF.Next() ) {
1491 TopoDS_Face F = TopoDS::Face( expF.Current() ) ;
1492 MapFacesAll.Add(F) ;
1493 TopExp_Explorer expW ;
1494 for( expW.Init( F, TopAbs_WIRE); expW.More(); expW.Next() ) {
1495 TopoDS_Wire W = TopoDS::Wire( expW.Current() ) ;
1496 if( MapHoles.Contains(W) ) {
1497 MapFacesToModify.Add(F) ;
1502 /* Define faces not modified */
1503 TopTools_MapOfShape MapFacesNotModified ;
1504 TopTools_MapIteratorOfMapOfShape it ;
1505 for( it.Initialize(MapFacesAll); it.More(); it.Next() ) {
1506 TopoDS_Face FF = TopoDS::Face( it.Key() ) ;
1507 if( !MapFacesToModify.Contains(FF) )
1508 MapFacesNotModified.Add(FF) ;
1511 if( MapFacesToModify.IsEmpty() )
1512 THROW_SALOME_CORBA_EXCEPTION("Error : empty map of faces", SALOME::BAD_PARAM);
1514 if( isFace && MapFacesToModify.Extent() != 1 )
1515 THROW_SALOME_CORBA_EXCEPTION("Incoherent", SALOME::BAD_PARAM);
1517 /* Main argument is a face */
1518 if( isFace && MapFacesToModify.Extent() == 1 ) {
1519 TopoDS_Face resultFace ;
1520 if( !RebuildFaceRemovingHoles( TopoDS::Face(tds), MapHoles, resultFace ) )
1521 THROW_SALOME_CORBA_EXCEPTION(" Problem : !RebuildFaceRemovingHoles()", SALOME::BAD_PARAM);
1522 /* Creation of CORBA object : face topology */
1523 result = CreateObject(resultFace);
1524 InsertInLabelOneArgument(tds, shapeFaceShell, resultFace, result, myCurrentOCAFDoc) ;
1528 /* Main argument is a shell : rebuild faces modified */
1529 TopTools_MapOfShape MapFacesModified ;
1530 for( it.Initialize(MapFacesToModify); it.More(); it.Next() ) {
1531 TopoDS_Face FF = TopoDS::Face( it.Key() ) ;
1533 if( !RebuildFaceRemovingHoles( FF, MapHoles, resF ) )
1534 THROW_SALOME_CORBA_EXCEPTION(" Problem shell : !RebuildFaceRemovingHoles()", SALOME::BAD_PARAM);
1535 MapFacesModified.Add(resF) ;
1538 /* Rebuild the shell with faces modified and non modified */
1539 TopoDS_Shell resultShell ;
1541 B.MakeShell(resultShell) ;
1542 TopTools_MapIteratorOfMapOfShape it1 ;
1543 for( it1.Initialize(MapFacesModified); it1.More(); it1.Next() )
1544 B.AddShellFace( resultShell,TopoDS::Face( it1.Key() ) ) ;
1545 for( it1.Initialize(MapFacesNotModified); it1.More(); it1.Next() )
1546 B.AddShellFace( resultShell,TopoDS::Face( it1.Key() ) ) ;
1548 B.CompleteShell(resultShell) ;
1550 if( resultShell.IsNull() )
1551 THROW_SALOME_CORBA_EXCEPTION("Null or not valid result Shell", SALOME::BAD_PARAM) ;
1553 /* Creation of CORBA object : shell topology */
1554 result = CreateObject(resultShell);
1555 InsertInLabelOneArgument(tds, shapeFaceShell, resultShell, result, myCurrentOCAFDoc) ;
1560 //================================================================================
1561 // function : RebuildFaceRemovingHoles()
1562 // purpose : Rebuild a face removing holes that are in 'mapHoles'.
1563 // : NB : 'mapHoles' may content more holes than necessary
1564 //================================================================================
1565 bool GEOM_Gen_i::RebuildFaceRemovingHoles( const TopoDS_Face& aFace,
1566 const TopTools_MapOfShape& mapHoles,
1567 TopoDS_Shape& resultFace )
1569 /* Get the outer wire of the face 'aFace' */
1570 TopoDS_Wire outW = BRepTools::OuterWire( aFace ) ;
1571 if( outW.IsNull() || !IsValid(outW) )
1572 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace : bad outer wire of 'aFace'", SALOME::BAD_PARAM);
1574 /* Rebuild a face avoiding holes in the map 'mapHoles' */
1575 Handle(Geom_Surface) Surface = BRep_Tool::Surface(aFace) ;
1576 TopoDS_Face F2 = BRepBuilderAPI_MakeFace( Surface, outW, true ) ;
1578 if( F2.Orientation() != aFace.Orientation() )
1579 F2.Orientation( aFace.Orientation() ) ;
1581 BRepBuilderAPI_MakeFace aBuilder( F2 ) ;
1582 bool foundAndKeepHoles = false ;
1583 TopExp_Explorer exp ;
1585 for( exp.Init( aFace, TopAbs_WIRE); exp.More(); exp.Next() ) {
1586 TopoDS_Wire hole = TopoDS::Wire( exp.Current() ) ;
1587 if( !mapHoles.Contains(hole) && !exp.Current().IsEqual(outW) ) {
1588 aBuilder.Add( hole) ;
1589 if( !aBuilder.IsDone() )
1590 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace : builder problem !", SALOME::BAD_PARAM);
1592 resultFace = TopoDS::Face(aBuilder) ;
1593 foundAndKeepHoles = true ;
1597 if( !foundAndKeepHoles )
1600 resultFace = TopoDS::Face(aBuilder) ;
1608 //================================================================================
1609 // function : SuppressHole() Main method.
1610 // purpose : Suppress an hole identified by a wire in a face of shape
1611 // : ListIdFace contains a unique index of face in shape
1612 // : ListIdWire contains a unique index of wire in face !!!
1613 // : ListIdEndFace is used only when hole traverse.
1614 //================================================================================
1615 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHole( GEOM::GEOM_Shape_ptr shape,
1616 const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdFace,
1617 const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdWire,
1618 const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdEndFace )
1619 throw (SALOME::SALOME_Exception)
1621 GEOM::GEOM_Shape_var result;
1624 TopoDS_Face endFace ;
1628 /* Retrieve 'aShape' the initial main shape selection */
1629 const TopoDS_Shape aShape = GetTopoShape(shape);
1631 if( !IsValid(aShape) )
1632 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : non valid main shape", SALOME::BAD_PARAM);
1634 if( ListIdFace.length() != 1 || ListIdWire.length() != 1 )
1635 THROW_SALOME_CORBA_EXCEPTION("bad list", SALOME::BAD_PARAM);
1637 /* Retrieve 'aFace' selection */
1638 if( !GetShapeFromIndex( aShape, TopAbs_FACE, ListIdFace[0], tmp ) ) {
1639 THROW_SALOME_CORBA_EXCEPTION("face not found", SALOME::BAD_PARAM);
1642 aFace = TopoDS::Face(tmp) ;
1644 if( !IsValid(aFace) )
1645 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : face shape not valid", SALOME::BAD_PARAM);
1647 /* Retrieve 'aWire' selection : Warning : index of wire refers to the face ! */
1649 if( !GetShapeFromIndex( aFace, TopAbs_WIRE, ListIdWire[0], aTmp ) ) {
1650 THROW_SALOME_CORBA_EXCEPTION("wire not found", SALOME::BAD_PARAM);
1653 aWire = TopoDS::Wire(aTmp) ;
1655 if( !IsValid(aWire) )
1656 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : bad wire" , SALOME::BAD_PARAM);
1658 /* Get the outer wire of aFace */
1659 TopoDS_Wire outerW = BRepTools::OuterWire( aFace ) ;
1660 if( outerW.IsNull() || !IsValid(outerW) )
1661 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : bad outer wire", SALOME::BAD_PARAM);
1663 /* Test bad user selection aWire */
1664 if( aWire.IsSame(outerW) )
1665 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : outerW = aWire", SALOME::BAD_PARAM);
1667 /* Test if 'endFace' is used as argument and seems to be a valid one */
1668 /* NB : 'endFace' is optional and used when hole to suppress traverse 'aShape' */
1669 if( ListIdEndFace.length() == 0 ) {
1670 withEndFace = false ;
1673 TopoDS_Shape aTemp ;
1674 if( !GetShapeFromIndex( aShape, TopAbs_FACE, ListIdEndFace[0], aTemp ) || tmp.IsNull() || !IsValid(aTemp) )
1675 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : non valid endFace", SALOME::BAD_PARAM);
1677 /* Test if 'endFace' as at least one hole */
1678 endFace = TopoDS::Face(aTemp) ;
1680 TopExp_Explorer fExp ;
1682 for( fExp.Init(endFace, TopAbs_WIRE); fExp.More(); fExp.Next() ) {
1683 TopoDS_Wire W = TopoDS::Wire( fExp.Current() ) ;
1684 if( !W.IsNull() && IsValid(W) )
1688 withEndFace = true ; /* at least 2 wires : outer wire plus an hole or more */
1690 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : end face selection ?", SALOME::BAD_PARAM);
1693 /* Find edges of aWire and test if degenerated */
1694 TopTools_SequenceOfShape SSedgesOfWire ;
1695 TopExp_Explorer wireExp ;
1696 for( wireExp.Init(aWire, TopAbs_EDGE); wireExp.More(); wireExp.Next() ) {
1697 TopoDS_Edge E = TopoDS::Edge( wireExp.Current() ) ;
1698 if( E.IsNull() || BRep_Tool::Degenerated(E) ) {
1699 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : found bad edge", SALOME::BAD_PARAM);
1702 SSedgesOfWire.Append( wireExp.Current() ) ;
1705 if( SSedgesOfWire.Length() < 1 )
1706 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : no edge(s) for aWire", SALOME::BAD_PARAM);
1708 /* Retrieve face ancestors of all edges of 'aWire' but avoiding 'aFace' */
1710 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgesFaces;
1711 TopTools_MapIteratorOfMapOfShape anIt ;
1712 TopTools_MapOfShape MFSuppress ;
1713 TopTools_MapOfShape MFSuppressTmp ;
1714 bool wireOnFace = false ;
1716 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aMapEdgesFaces) ;
1717 for( int h=1; h<=SSedgesOfWire.Length(); h++ ) {
1719 TopoDS_Shape anEdgeOfWire = SSedgesOfWire.Value(h) ;
1720 int ind = aMapEdgesFaces.FindIndex(anEdgeOfWire) ;
1722 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : index of edge", SALOME::BAD_PARAM);
1724 TopTools_ListOfShape LF;
1725 LF = aMapEdgesFaces.FindFromIndex(ind) ; /* Contains all faces ancestors of an edge of wire */
1727 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : no face for an edge", SALOME::BAD_PARAM);
1729 /* Filter faces avoiding 'aFace' */
1730 TopTools_ListIteratorOfListOfShape it ;
1731 for( it.Initialize(LF); it.More(); it.Next() ) {
1732 TopoDS_Face F = TopoDS::Face( it.Value() ) ;
1733 if( !F.IsSame(aFace) ) {
1734 MFSuppressTmp.Add(F) ;
1744 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : wire not on selected face", SALOME::BAD_PARAM);
1747 /* Call routine to define faces to suppress and and optional endWire on endFace */
1748 TopTools_MapOfShape MSwireEndEdges ; /* will contain edges of final wire (hole) */
1749 SuppressHoleSubRoutine( aShape, aFace, SSedgesOfWire, aMapEdgesFaces, MFSuppressTmp, MFSuppress, withEndFace, endFace, MSwireEndEdges ) ;
1751 TopoDS_Wire endWire ;
1754 if( MSwireEndEdges.Extent() < 1 )
1755 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : MSwireEndEdges.Extent() < 1", SALOME::BAD_PARAM);
1757 if( !FindCompareWireHoleOnFace( endFace, MSwireEndEdges, endWire ) )
1758 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : no endWire found", SALOME::BAD_PARAM);
1761 /* Build 'resTds' : a shape containing a compound of faces */
1762 TopoDS_Shape resTds;
1763 if( !withEndFace && !BuildShapeHoleNotTraversing( aShape, aFace, aWire, MFSuppress, resTds ) )
1764 THROW_SALOME_CORBA_EXCEPTION("Rebuild result shape has aborted", SALOME::BAD_PARAM);
1766 if( withEndFace && !BuildShapeHoleTraversing( aShape, aFace, aWire, MFSuppress, endFace, endWire, resTds ) )
1767 THROW_SALOME_CORBA_EXCEPTION("Rebuild result shape has aborted (end hole)", SALOME::BAD_PARAM);
1769 /* Reconstruction of final shape with 'resTds' : a compound of faces after hole suppressing */
1770 /* Actual limitation is : 'aShape' must not contain more than a solid or a shell ! */
1771 TopoDS_Shape finalShape ;
1773 TopExp_Explorer exp ;
1774 unsigned int nbSolid = 0 ;
1775 TopoDS_Solid aSolid ;
1776 for( exp.Init(aShape, TopAbs_SOLID); exp.More(); exp.Next() ) {
1777 aSolid = TopoDS::Solid( exp.Current() ) ;
1780 THROW_SALOME_CORBA_EXCEPTION("Limitation : main shape contents more than one solid", SALOME::BAD_PARAM);
1783 unsigned int nbShell = 0 ;
1784 TopoDS_Shell aShell ;
1785 for( exp.Init(aShape, TopAbs_SHELL); exp.More(); exp.Next() ) {
1786 aShell = TopoDS::Shell( exp.Current() ) ;
1789 THROW_SALOME_CORBA_EXCEPTION("Limitation : main shape contents more than one shell", SALOME::BAD_PARAM);
1792 /* No shells and no solids : can send a compound even for a single face, see GUI ! */
1793 if( nbShell == 0 ) {
1794 finalShape = resTds ;
1798 TopoDS_Shell shellResult ;
1799 if( nbShell == 1 ) {
1800 if ( !BuildShellWithFaceCompound( TopoDS::Compound(resTds), shellResult ) )
1801 THROW_SALOME_CORBA_EXCEPTION("Error after BuildShellWithFaceCompound()", SALOME::BAD_PARAM);
1802 finalShape = shellResult ;
1805 /* a solid with a shell */
1806 if( nbSolid == 1 && nbShell == 1) {
1807 BRepBuilderAPI_MakeSolid B;
1808 B.Add(shellResult) ;
1810 THROW_SALOME_CORBA_EXCEPTION("Error : !B.IsDone()", SALOME::BAD_PARAM);
1811 finalShape = B.Solid() ;
1814 result = CreateObject(finalShape);
1815 InsertInLabelOneArgument(aShape, shape, finalShape, result, myCurrentOCAFDoc) ;
1821 //================================================================================
1822 // function : BuildShellWithFaceCompound()
1823 // purpose : Build a shell with a compound of faces.
1824 //================================================================================
1825 bool GEOM_Gen_i::BuildShellWithFaceCompound( const TopoDS_Compound Comp,
1826 TopoDS_Shell& resultShell )
1828 resultShell.Nullify() ;
1829 BRepPrim_Builder B ;
1830 B.MakeShell(resultShell) ;
1831 TopExp_Explorer ex ;
1833 for( ex.Init( Comp, TopAbs_FACE); ex.More(); ex.Next() ) {
1834 TopoDS_Face F = TopoDS::Face( ex.Current() ) ;
1838 B.AddShellFace( resultShell, F ) ;
1840 B.CompleteShell(resultShell) ;
1841 if( resultShell.IsNull() ) {
1848 //================================================================================
1849 // function : FindCompareWireHoleOnFace()
1850 // purpose : Try to find a wire on 'aFace' which edges are same than those
1851 // : into 'MSwireEdges' map. 'aFoundWire' is defined and 'true' returned.
1852 // : 'MSwireEdges' represents generally an hole an 'aFace'.
1853 // : The outer wire of 'aFace' is avoided !
1854 //================================================================================
1855 bool GEOM_Gen_i::FindCompareWireHoleOnFace( const TopoDS_Face& F,
1856 const TopTools_MapOfShape& MSwireEdges,
1857 TopoDS_Wire& aFoundWire )
1859 aFoundWire.Nullify() ;
1864 /* Get the outer wire of aFace */
1865 TopoDS_Wire outerW = BRepTools::OuterWire(F) ;
1866 if( outerW.IsNull() || !IsValid(outerW) ) {
1870 int nbEdges = MSwireEdges.Extent() ;
1875 TopExp_Explorer exp1 ;
1876 TopExp_Explorer exp2 ;
1877 for ( exp1.Init(F, TopAbs_WIRE) ; exp1.More(); exp1.Next() ) {
1878 TopoDS_Wire W = TopoDS::Wire( exp1.Current() ) ;
1880 if( !W.IsSame(outerW) ) {
1881 for ( exp2.Init( W, TopAbs_EDGE) ; exp2.More(); exp2.Next() ) {
1882 TopoDS_Edge E = TopoDS::Edge( exp2.Current() ) ;
1883 if( MSwireEdges.Contains(E) ) {
1885 if( i == nbEdges ) {
1897 //================================================================================
1898 // function : BuildShapeHoleNotTraversing()
1899 // purpose : Define 'resultTds' a reconstruction of 'aShape' after modification
1900 // : on 'aFace' where 'aWire is removed' and suppression of faces 'MFSuppress'
1901 // : ( Used as a sub routine of SuppressHole() )
1902 //================================================================================
1903 bool GEOM_Gen_i::BuildShapeHoleNotTraversing( const TopoDS_Shape& aShape,
1904 const TopoDS_Face& aFace,
1905 const TopoDS_Wire& aWire,
1906 const TopTools_MapOfShape& MFSuppress,
1907 TopoDS_Shape& resultTds )
1908 throw (SALOME::SALOME_Exception)
1911 TopExp_Explorer exp ;
1912 TopoDS_Face newFace ;
1914 resultTds.Nullify() ;
1915 TopoDS_Compound Comp ;
1916 B.MakeCompound (Comp);
1920 /* Explore all faces of 'aShape' to rebuild a compound */
1921 for ( exp.Init(aShape, TopAbs_FACE) ; exp.More(); exp.Next() ) {
1923 TopoDS_Face F1 = TopoDS::Face( exp.Current() );
1924 /* Rebuild face(s) not suppressed */
1925 if( !MFSuppress.Contains(F1) ) {
1927 if( F1.IsEqual( aFace ) ) {
1928 TopTools_MapOfShape MSwire ;
1930 if( !RebuildFaceRemovingHoles(aFace, MSwire, newFace) ) {
1933 B.Add( Comp, newFace ) ;
1936 /* For any other face not suppressed */
1942 catch(Standard_Failure) {
1943 THROW_SALOME_CORBA_EXCEPTION("in BuildShapeHoleNotTraversing() : Exception catched", SALOME::BAD_PARAM);
1951 //================================================================================
1952 // function : BuildShapeHoleTraversing()
1953 // purpose : Define 'resultTds' a reconstruction of 'aShape' after modifications.
1954 // : On 'aFace' 'aWire is removed'
1955 // : On 'endFace' 'endWire' is removed.
1956 // : Faces of 'MFSuppress' are removed.
1957 // : ( Used as a sub routine of SuppressHole() )
1958 //================================================================================
1959 bool GEOM_Gen_i::BuildShapeHoleTraversing( const TopoDS_Shape& aShape,
1960 const TopoDS_Face& aFace,
1961 const TopoDS_Wire& aWire,
1962 const TopTools_MapOfShape& MFSuppress,
1963 const TopoDS_Face& endFace,
1964 const TopoDS_Wire& endWire,
1965 TopoDS_Shape& resultTds )
1966 throw (SALOME::SALOME_Exception)
1969 TopExp_Explorer exp ;
1970 TopoDS_Face newFace ;
1972 resultTds.Nullify() ;
1973 TopoDS_Compound Comp ;
1974 B.MakeCompound (Comp);
1976 /* Necessary to use general method */
1977 TopTools_MapOfShape MSwire1 ;
1978 MSwire1.Add(aWire) ;
1979 TopTools_MapOfShape MSwire2 ;
1980 MSwire2.Add(endWire) ;
1984 /* Explore all faces of 'aShape' to rebuild a compound */
1985 for ( exp.Init(aShape, TopAbs_FACE) ; exp.More(); exp.Next() ) {
1986 TopoDS_Face F1 = TopoDS::Face( exp.Current() );
1988 /* Rebuild face(s) not suppressed */
1989 if( !MFSuppress.Contains(F1) ) {
1991 /* Rebuild 'aFace' */
1992 if( F1.IsEqual( aFace ) && !F1.IsEqual( endFace ) ) {
1993 if( !RebuildFaceRemovingHoles(aFace, MSwire1, newFace) ) {
1996 B.Add(Comp, newFace) ;
1999 /* Rebuild 'endFace' */
2000 if( !F1.IsEqual( aFace ) && F1.IsEqual( endFace ) ) {
2001 if( !RebuildFaceRemovingHoles(endFace, MSwire2, newFace) ) {
2004 B.Add(Comp, newFace) ;
2007 /* Hole in the same face : aFace = endFace */
2008 if( F1.IsEqual( aFace ) && F1.IsEqual( endFace ) ) {
2010 if( !RebuildFaceRemovingHoles(aFace, MSwire1, newFace) || !RebuildFaceRemovingHoles(newFace, MSwire2, FF) ) {
2016 /* For any other face not suppressed */
2017 if( !F1.IsEqual(aFace) && !F1.IsEqual( endFace ) ) {
2024 catch(Standard_Failure) {
2025 THROW_SALOME_CORBA_EXCEPTION("in BuildShapeHoleTraversing() : Exception catched", SALOME::BAD_PARAM);
2031 //=======================================================================
2032 //function : SortShapes
2034 //=======================================================================
2036 static void SortShapes(TopTools_ListOfShape& SL)
2038 Standard_Integer MaxShapes = SL.Extent();
2039 TopTools_Array1OfShape aShapes (1,MaxShapes);
2040 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
2041 TColStd_Array1OfReal MidXYZ (1,MaxShapes); //X,Y,Z;
2042 TColStd_Array1OfReal Length (1,MaxShapes); //X,Y,Z;
2044 // Computing of CentreOfMass
2045 Standard_Integer Index;
2048 TopTools_ListIteratorOfListOfShape it(SL);
2049 for (Index=1; it.More(); Index++)
2051 TopoDS_Shape S = it.Value();
2052 SL.Remove( it ); // == it.Next()
2054 OrderInd.SetValue (Index, Index);
2055 if (S.ShapeType() == TopAbs_VERTEX)
2057 GPoint = BRep_Tool::Pnt( TopoDS::Vertex( S ));
2058 Length.SetValue( Index, (Standard_Real) S.Orientation());
2062 BRepGProp::LinearProperties (S, GPr);
2063 GPoint = GPr.CentreOfMass();
2064 Length.SetValue( Index, GPr.Mass() );
2066 MidXYZ.SetValue(Index,
2067 GPoint.X()*999 + GPoint.Y()*99 + GPoint.Z()*0.9);
2070 Standard_Integer aTemp;
2071 Standard_Boolean exchange, Sort = Standard_True;
2074 Sort = Standard_False;
2075 for (Index=1; Index < MaxShapes; Index++)
2077 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1)))
2078 exchange = Standard_True;
2079 else if (MidXYZ(OrderInd(Index)) == MidXYZ(OrderInd(Index+1)) &&
2080 Length(OrderInd(Index)) > Length(OrderInd(Index+1)) )
2081 exchange = Standard_True;
2083 exchange = Standard_False;
2086 aTemp = OrderInd(Index);
2087 OrderInd(Index) = OrderInd(Index+1);
2088 OrderInd(Index+1) = aTemp;
2089 Sort = Standard_True;
2093 for (Index=1; Index <= MaxShapes; Index++)
2094 SL.Append( aShapes( OrderInd(Index) ));
2097 //================================================================================
2098 // function : SubShape()
2099 // purpose : Method for GUI or TUI
2100 //================================================================================
2102 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShape(GEOM::GEOM_Shape_ptr shape,
2103 CORBA::Short ShapeType,
2104 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID)
2105 throw (SALOME::SALOME_Exception)
2107 return SubShapesOne(shape, (TopAbs_ShapeEnum) ShapeType, ListOfID);
2110 //================================================================================
2111 // function : SubShapeSorted()
2112 // purpose : Method for GUI or TUI
2113 //================================================================================
2115 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShapeSorted(GEOM::GEOM_Shape_ptr shape,
2116 CORBA::Short ShapeType,
2117 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID)
2118 throw (SALOME::SALOME_Exception)
2120 return SubShapesOne(shape, (TopAbs_ShapeEnum) ShapeType, ListOfID, Standard_True);
2123 //================================================================================
2124 // function : SubShapesOne()
2126 //================================================================================
2128 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShapesOne( GEOM::GEOM_Shape_ptr shape,
2129 const TopAbs_ShapeEnum ShapeType,
2130 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID,
2131 const Standard_Boolean Sort)
2132 throw (SALOME::SALOME_Exception)
2134 GEOM::GEOM_Shape_var result;
2135 TopoDS_Shape mainShape;
2136 TopoDS_Shape mainTopo = GetTopoShape(shape);
2140 if ( shape->IsMainShape() ) {
2141 mainShape = GetTopoShape(shape);
2144 shape = GetIORFromString( shape->MainName() );
2147 if(ListOfID.length() < 1) {
2148 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SubShape() : bad list of shapes",
2152 /* Create a sequence of all sub shapes */
2153 TopTools_ListOfShape listShape;
2155 TopTools_MapOfShape mapShape;
2156 TopExp_Explorer exp ;
2157 for ( exp.Init( mainShape, TopAbs_ShapeEnum(ShapeType)) ; exp.More(); exp.Next() ) {
2158 if ( mapShape.Add( exp.Current() ) )
2159 listShape.Append ( exp.Current() );
2162 if (listShape.IsEmpty()) return shape;
2165 SortShapes(listShape);
2167 TopTools_SequenceOfShape SS;
2168 TopTools_ListIteratorOfListOfShape it (listShape);
2169 for (; it.More(); it.Next())
2170 SS.Append( it.Value() );
2172 TopoDS_Shape SubShape;
2173 if (ListOfID.length() == 1)
2174 SubShape = SS.Value(ListOfID[0]);
2178 TopoDS_Compound Comp;
2179 B.MakeCompound (Comp);
2181 for ( ind = 0; ind < ListOfID.length(); ind++ )
2182 B.Add( Comp, SS.Value(ListOfID[ind]) );
2186 if ( !TNaming_Tool::HasLabel( myCurrentOCAFDoc->Main(), SubShape ) )
2187 result = CreateSubObject( SubShape, shape, ListOfID);
2190 TDF_Label Lab = TNaming_Tool::Label( myCurrentOCAFDoc->Main(), SubShape, TransDef );
2191 Handle(TDataStd_Name) Att;
2192 if ( Lab.FindAttribute( TDataStd_Name::GetID(), Att ) ) {
2193 TCollection_AsciiString nameIOR( Att->Get() );
2194 result = GEOM::GEOM_Shape::_narrow(_orb->string_to_object( nameIOR.ToCString() ));
2195 if ( strcmp( result->MainName(), _orb->object_to_string(shape) ) != 0 ) {
2196 result = CreateSubObject( SubShape, shape, ListOfID);
2205 //================================================================================
2206 // function : SubShapeAll()
2207 // purpose : Explode a shape in all sub shapes with a type (Method for TUI or GUI)
2208 //================================================================================
2210 GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapeAll(GEOM::GEOM_Shape_ptr shape,
2211 CORBA::Short ShapeType)
2212 throw (SALOME::SALOME_Exception)
2214 return SubShapesAll(shape, (TopAbs_ShapeEnum) ShapeType);
2217 //================================================================================
2218 // function : SubShapeAllSorted()
2219 // purpose : Explode a shape in all sub shapes with a type (Method for TUI or GUI)
2220 //================================================================================
2222 GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapeAllSorted(GEOM::GEOM_Shape_ptr shape,
2223 CORBA::Short ShapeType)
2224 throw (SALOME::SALOME_Exception)
2226 return SubShapesAll(shape, (TopAbs_ShapeEnum) ShapeType, Standard_True);
2229 //================================================================================
2230 // function : SubShapeAllSorted()
2232 //================================================================================
2234 GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapesAll(GEOM::GEOM_Shape_ptr shape,
2235 const TopAbs_ShapeEnum ShapeType,
2236 const Standard_Boolean Sort)
2237 throw (SALOME::SALOME_Exception)
2239 /* List of sub shapes returned */
2240 GEOM::GEOM_Gen::ListOfGeomShapes_var listOfGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
2241 listOfGeomShapes->length(0) ;
2243 TopoDS_Shape mainTopo = GetTopoShape(shape);
2244 TopoDS_Shape mainShape;
2247 if ( shape->IsMainShape() ) {
2248 mainShape = GetTopoShape(shape);
2251 shape = GetIORFromString( shape->MainName() );
2254 if( mainTopo.IsNull() ) {
2255 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SubShapeAll() : null main shape",
2259 /* List/index : field set for any sub shape */
2260 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
2261 ListOfID->length(1) ;
2263 // retrieve all subshapes
2264 TopTools_MapOfShape mapShape;
2265 TopTools_ListOfShape listShape;
2267 if (mainTopo.ShapeType()==TopAbs_COMPOUND && ShapeType==TopAbs_SHAPE)
2269 TopoDS_Iterator It(mainTopo,Standard_True,Standard_True );
2270 for ( ; It.More(); It.Next() )
2271 if (mapShape.Add( It.Value() ))
2272 listShape.Append( It.Value() );
2276 TopExp_Explorer exp ( mainTopo, ShapeType);
2277 for ( ; exp.More(); exp.Next() )
2278 if (mapShape.Add( exp.Current() ))
2279 listShape.Append( exp.Current() );
2283 SortShapes(listShape);
2285 /* Create all sub shapes */
2287 GEOM::GEOM_Shape_var result;
2289 TopTools_ListIteratorOfListOfShape itSub (listShape);
2290 for (index = 1; itSub.More(); itSub.Next(), ++index)
2292 const TopoDS_Shape& SubShape = itSub.Value();
2293 // check if SubShape is already in OCAFDS and ...
2294 if ( TNaming_Tool::HasLabel( myCurrentOCAFDoc->Main(), SubShape ) )
2297 TDF_Label Lab = TNaming_Tool::Label( myCurrentOCAFDoc->Main(), SubShape, TransDef );
2298 Handle(TDataStd_Name) Att;
2299 if ( Lab.FindAttribute( TDataStd_Name::GetID(), Att ) )
2301 TCollection_AsciiString nameIOR( Att->Get() );
2302 result = GEOM::GEOM_Shape::_narrow(_orb->string_to_object( nameIOR.ToCString() ));
2303 // ... it is subshape of <shape>
2304 if ( strcmp( result->MainName(), _orb->object_to_string(shape) ) == 0 )
2306 listOfGeomShapes->length(index) ;
2307 listOfGeomShapes[index-1] = result ;
2314 // ListOfID[0] = index;
2316 ListOfID[0] = GetIndexTopology( SubShape, mainShape ) ;
2317 result = CreateSubObject( SubShape, shape, ListOfID);
2318 /* Add each sub shape in the list returned */
2319 listOfGeomShapes->length(index) ;
2320 listOfGeomShapes[index-1] = result ;
2323 return listOfGeomShapes._retn() ;
2327 //=================================================================================
2328 // function : MakeBoolean()
2329 // purpose : Boolean operation according to the type 'operation'
2330 //=================================================================================
2331 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeBoolean(GEOM::GEOM_Shape_ptr shape1,
2332 GEOM::GEOM_Shape_ptr shape2,
2333 CORBA::Long operation)
2334 throw (SALOME::SALOME_Exception)
2336 GEOM::GEOM_Shape_var result;
2337 TopoDS_Shape shape ;
2338 TopoDS_Shape aShape1 ;
2339 TopoDS_Shape aShape2 ;
2342 aShape1 = GetTopoShape(shape1) ;
2343 aShape2 = GetTopoShape(shape2) ;
2345 if( aShape1.IsNull() || aShape2.IsNull() ) {
2346 THROW_SALOME_CORBA_EXCEPTION("Boolean aborted : argument shape is null", SALOME::BAD_PARAM);
2351 case 1 : /* Common */
2352 shape = BRepAlgoAPI_Common(aShape1, aShape2).Shape();
2355 shape = BRepAlgoAPI_Cut(aShape1, aShape2).Shape();
2358 shape = BRepAlgoAPI_Fuse(aShape1, aShape2).Shape();
2360 case 4 : /* Section */
2361 shape = BRepAlgoAPI_Section(aShape1, aShape2).Shape();
2364 MESSAGE("Boolean operation not known : " << operation ) ;
2368 catch(Standard_Failure) {
2369 THROW_SALOME_CORBA_EXCEPTION("Exception catched in boolean operation", SALOME::BAD_PARAM);
2372 /* We test the validity of resulting shape */
2373 if( !IsValid(shape) ) {
2374 THROW_SALOME_CORBA_EXCEPTION("Boolean aborted : non valid shape result", SALOME::BAD_PARAM);
2377 result = CreateObject(shape) ;
2379 /* put shape and name into geom/OCAF doc */
2380 GEOMDS_Commands GC(myCurrentOCAFDoc->Main());
2381 /* add attributs 'shape' and' name_io'r in a new label */
2382 TDF_Label Lab = GC.Generated(aShape1, shape, result->Name() );
2383 TCollection_AsciiString entry;
2384 TDF_Tool::Entry(Lab, entry);
2385 result->ShapeId( entry.ToCString() ) ;
2387 /* Create a new label */
2388 TDF_Label NewLab = Lab.NewChild();
2389 TCollection_ExtendedString Value("Arguments");
2390 TDataStd_Name::Set(NewLab,Value);
2392 TDF_Label NewLab1 = NewLab.NewChild();
2394 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), shape1->ShapeId(), RefLab);
2395 TDF_Reference::Set(NewLab1, RefLab);
2397 TDF_Label NewLab2 = NewLab.NewChild();
2398 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), shape2->ShapeId(), RefLab);
2399 TDF_Reference::Set(NewLab2, RefLab);
2404 //=================================================================================
2405 // function : MakeFuse()
2406 // purpose : Special purpose !
2407 //=================================================================================
2408 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFuse(GEOM::GEOM_Shape_ptr shape1,
2409 GEOM::GEOM_Shape_ptr shape2)
2410 throw (SALOME::SALOME_Exception)
2412 GEOM::GEOM_Shape_var result;
2413 TopoDS_Shape aShape1 = GetTopoShape(shape1) ;
2414 TopoDS_Shape aShape2 = GetTopoShape(shape2) ;
2415 if( aShape1.IsNull() || aShape2.IsNull() ) {
2416 THROW_SALOME_CORBA_EXCEPTION("Fuse aborted : shape in argument is null", SALOME::BAD_PARAM);
2420 shape = BRepAlgoAPI_Fuse(aShape1, aShape2).Shape();
2422 catch(Standard_Failure) {
2423 THROW_SALOME_CORBA_EXCEPTION("Exception catched in Fuse operation", SALOME::BAD_PARAM);
2426 /* We test the validity of resulting shape */
2427 if( !IsValid(shape) ) {
2428 THROW_SALOME_CORBA_EXCEPTION("Fuse aborted : non valid shape result", SALOME::BAD_PARAM);
2431 result = CreateObject(shape) ;
2433 /* put shape and name into geom/OCAF doc */
2434 GEOMDS_Commands GC(myCurrentOCAFDoc->Main());
2435 /* add attributs 'shape' and' name_io'r in a new label */
2436 TDF_Label Lab = GC.Generated(aShape1, shape, result->Name() );
2437 TCollection_AsciiString entry;
2438 TDF_Tool::Entry(Lab, entry);
2439 result->ShapeId( entry.ToCString() ) ;
2441 /* Create a new label */
2442 TDF_Label NewLab = Lab.NewChild();
2443 TCollection_ExtendedString Value("Arguments");
2444 TDataStd_Name::Set(NewLab,Value);
2446 TDF_Label NewLab1 = NewLab.NewChild();
2448 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), shape1->ShapeId(), RefLab);
2449 TDF_Reference::Set(NewLab1, RefLab);
2451 TDF_Label NewLab2 = NewLab.NewChild();
2452 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), shape2->ShapeId(), RefLab);
2453 TDF_Reference::Set(NewLab2, RefLab);
2458 //================================================================================
2459 // function : MakeAxisStruct()
2460 // purpose : Create a structure GEOM::AxisStruct (see IDL file)
2461 //================================================================================
2462 GEOM::AxisStruct GEOM_Gen_i::MakeAxisStruct(CORBA::Double x,
2469 GEOM::AxisStruct A ;
2470 A.x = x ; A.y = y ; A.z = z ;
2471 A.vx = vx ; A.vy = vy ; A.vz = vz ;
2476 //================================================================================
2477 // function : MakePointStruct()
2478 // purpose : Create a structure GEOM::PointStruct (see IDL file)
2479 //================================================================================
2480 GEOM::PointStruct GEOM_Gen_i::MakePointStruct(CORBA::Double x,
2484 beginService( "GEOM_Gen_i::MakePointStruct" );
2485 GEOM::PointStruct p ;
2486 p.x = x ; p.y = y ; p.z = z ;
2487 endService( "GEOM_Gen_i::MakePointStruct" );
2491 //================================================================================
2492 // function : MakeDirection()
2493 // purpose : Create a structure GEOM::DirStruct (see IDL file)
2494 //================================================================================
2495 GEOM::DirStruct GEOM_Gen_i::MakeDirection(const GEOM::PointStruct& p)
2498 d.PS.x = p.x ; d.PS.y = p.y ; d.PS.z = p.z ;
2502 //=================================================================================
2503 // function : MakeBox()
2504 // purpose : Create a box topology.
2505 //=================================================================================
2506 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeBox(CORBA::Double x1,
2512 throw (SALOME::SALOME_Exception)
2514 gp_Pnt P1(x1,y1,z1);
2515 gp_Pnt P2(x2,y2,z2);
2516 GEOM::GEOM_Shape_var result ;
2519 tds = BRepPrimAPI_MakeBox(P1,P2).Shape();
2521 catch(Standard_Failure) {
2522 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeBox", SALOME::BAD_PARAM);
2526 THROW_SALOME_CORBA_EXCEPTION("Make Box aborted : null shape", SALOME::BAD_PARAM);
2529 result = CreateObject(tds);
2530 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2531 result->ShapeId(entry) ;
2536 //================================================================================
2537 // function : MakeCylinder
2538 // purpose : Create a cylinder topology
2539 //================================================================================
2540 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCylinder(const GEOM::PointStruct& pstruct,
2541 const GEOM::DirStruct& dstruct,
2542 CORBA::Double radius,
2543 CORBA::Double height)
2544 throw (SALOME::SALOME_Exception)
2546 GEOM::GEOM_Shape_var result;
2548 gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ;
2549 gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
2553 tds = BRepPrimAPI_MakeCylinder(axis, radius, height).Shape();
2555 catch(Standard_Failure) {
2556 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeCylinder", SALOME::BAD_PARAM);
2560 THROW_SALOME_CORBA_EXCEPTION("Make Cylinder aborted", SALOME::BAD_PARAM);
2562 result = CreateObject(tds);
2563 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2564 result->ShapeId(entry);
2570 //================================================================================
2571 // function : MakeSphere()
2572 // purpose : Make a sphere topology
2573 //================================================================================
2574 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSphere(CORBA::Double x1,
2577 CORBA::Double radius)
2578 throw (SALOME::SALOME_Exception)
2580 GEOM::GEOM_Shape_var result ;
2583 tds = BRepPrimAPI_MakeSphere(gp_Pnt(x1,y1,z1), radius).Shape();
2585 catch(Standard_Failure) {
2586 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeSphere", SALOME::BAD_PARAM);
2590 THROW_SALOME_CORBA_EXCEPTION("Make Sphere aborted", SALOME::BAD_PARAM);
2592 result = CreateObject(tds) ;
2593 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2594 result->ShapeId(entry);
2600 //================================================================================
2601 // function : MakeTorus()
2602 // purpose : Create a torus topology
2603 //================================================================================
2604 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeTorus( const GEOM::PointStruct& pstruct,
2605 const GEOM::DirStruct& dstruct,
2606 CORBA::Double major_radius,
2607 CORBA::Double minor_radius )
2608 throw (SALOME::SALOME_Exception)
2610 GEOM::GEOM_Shape_var result;
2612 gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ;
2613 gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
2617 tds = BRepPrimAPI_MakeTorus(axis, major_radius, minor_radius).Shape();
2619 catch(Standard_Failure) {
2620 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeTorus", SALOME::BAD_PARAM);
2624 THROW_SALOME_CORBA_EXCEPTION("Make torus aborted", SALOME::BAD_PARAM);
2626 result = CreateObject(tds);
2627 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2628 result->ShapeId(entry);
2633 //================================================================================
2634 // function : MakeCone()
2635 // purpose : Create a cone topology
2636 //================================================================================
2637 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCone(const GEOM::PointStruct& pstruct,
2638 const GEOM::DirStruct& dstruct,
2639 CORBA::Double radius1,
2640 CORBA::Double radius2,
2641 CORBA::Double height)
2642 throw (SALOME::SALOME_Exception)
2644 GEOM::GEOM_Shape_var result;
2646 gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ;
2647 gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
2651 /* Cone doesn't work if same radius */
2652 if( fabs(radius1-radius2) <= Precision::Confusion() ) {
2653 tds = BRepPrimAPI_MakeCylinder(axis, (radius1+radius2)/2.0, height).Shape();
2656 tds = BRepPrimAPI_MakeCone(axis, radius1, radius2, height).Shape();
2659 catch(Standard_Failure) {
2660 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeCone", SALOME::BAD_PARAM);
2664 THROW_SALOME_CORBA_EXCEPTION("Make Cone aborted", SALOME::BAD_PARAM);
2666 result = CreateObject(tds);
2667 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2668 result->ShapeId(entry);
2674 //==================================================================================
2675 // function : ImportIGES()
2676 // purpose : Import shape from an IGES (IGS) file
2677 // : LPN modified 7 mai 2002
2678 //==================================================================================
2679 GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportIGES(const char* filename)
2680 throw (SALOME::SALOME_Exception)
2682 GEOM::GEOM_Shape_var result ;
2683 //VRV: OCC 4.0 migration
2684 IGESControl_Reader aReader;
2685 //VRV: OCC 4.0 migration
2687 IFSelect_ReturnStatus stat = aReader.ReadFile((char*)filename);
2688 if ( stat != IFSelect_RetDone ) {
2689 THROW_SALOME_CORBA_EXCEPTION("Error in reading import file", SALOME::BAD_PARAM); }
2691 MESSAGE("ImportIGES : all Geometry Transfer" << endl ) ;
2693 aReader.TransferRoots(false);
2695 MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes() << endl );
2696 TopoDS_Shape shape = aReader.OneShape();
2698 if ( !shape.IsNull() ) {
2699 /* Final CORBA object creation */
2700 result = CreateObject(shape) ;
2701 const char *entry = InsertInLabel( shape, result->Name(), myCurrentOCAFDoc ) ;
2702 result->ShapeId(entry);
2706 catch(Standard_Failure) {
2707 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportIGES()", SALOME::BAD_PARAM);
2710 THROW_SALOME_CORBA_EXCEPTION("Import IGES aborted : internal error", SALOME::BAD_PARAM);
2715 //==================================================================================
2716 // function : ImportSTEP()
2717 // purpose : Import shape from an STEP (stp) file
2718 // : 'result' is a compound of shapes if file contains more entities.
2719 //==================================================================================
2720 GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportSTEP(const char* filename)
2721 throw (SALOME::SALOME_Exception)
2723 GEOM::GEOM_Shape_var result ;
2724 //VRV: OCC 4.0 migration
2725 STEPControl_Reader aReader;
2726 //VRV: OCC 4.0 migration
2728 TopoDS_Compound compound;
2730 B.MakeCompound( compound );
2733 IFSelect_ReturnStatus status = aReader.ReadFile((char*)filename);
2735 if (status == IFSelect_RetDone) {
2736 Standard_Boolean failsonly = Standard_False ;
2737 aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
2738 /* Root transfers */
2739 Standard_Integer nbr = aReader.NbRootsForTransfer();
2740 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
2742 for ( Standard_Integer n=1; n <= nbr; n++) {
2744 Standard_Boolean ok = aReader.TransferRoot(n);
2745 /* Collecting resulting entities */
2746 Standard_Integer nbs = aReader.NbShapes();
2748 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
2750 for ( Standard_Integer i=1; i<=nbs; i++ ) {
2751 TopoDS_Shape aShape = aReader.Shape(i);
2752 if ( aShape.IsNull() )
2753 THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
2755 /* For a single entity */
2756 if(nbr == 1 && nbs == 1) {
2757 result = CreateObject(aShape) ;
2758 const char *entry = InsertInLabel(aShape, result->Name(), myCurrentOCAFDoc) ;
2759 result->ShapeId(entry);
2763 B.Add( compound, aShape ) ;
2768 TopoDS_Shape tds = compound ;
2769 result = CreateObject(tds) ;
2770 if( CORBA::is_nil(result) )
2771 THROW_SALOME_CORBA_EXCEPTION("Translation aborted : null result", SALOME::BAD_PARAM);
2772 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2773 result->ShapeId(entry);
2778 catch(Standard_Failure) {
2779 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
2785 //==================================================================================
2786 // function : Partition()
2788 //==================================================================================
2790 GEOM::GEOM_Shape_ptr
2791 GEOM_Gen_i::Partition(const GEOM::GEOM_Gen::ListOfIOR& ListShapes,
2792 const GEOM::GEOM_Gen::ListOfIOR& ListTools,
2793 const GEOM::GEOM_Gen::ListOfIOR& ListKeepInside,
2794 const GEOM::GEOM_Gen::ListOfIOR& ListRemoveInside,
2795 const CORBA::Short Limit)
2796 throw (SALOME::SALOME_Exception)
2798 GEOM::GEOM_Shape_var aResult;
2800 //MESSAGE ("In Partition");
2803 unsigned int ind, nbshapes = 0;
2804 nbshapes += ListShapes.length() + ListTools.length();
2805 nbshapes += ListKeepInside.length() + ListRemoveInside.length();
2807 Partition_Spliter PS;
2808 TopTools_MapOfShape ShapesMap(nbshapes), ToolsMap(nbshapes);
2810 // add object shapes that are in ListShapes;
2811 for ( ind = 0; ind < ListShapes.length(); ind++) {
2813 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[ind] );
2814 TopoDS_Shape Shape = GetTopoShape(aShape);
2815 if(Shape.IsNull() ) {
2816 //MESSAGE ( "In Partition a shape is null" );
2817 THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM);
2819 if ( ShapesMap.Add( Shape ))
2823 // add tool shapes that are in ListTools and not in ListShapes;
2824 for (ind = 0; ind < ListTools.length(); ind++) {
2826 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListTools[ind] );
2827 TopoDS_Shape Shape = GetTopoShape(aShape);
2828 if(Shape.IsNull() ) {
2829 //MESSAGE ( "In Partition a tool shape is null" );
2830 THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM);
2832 if ( !ShapesMap.Contains( Shape ) && ToolsMap.Add( Shape ))
2836 // add shapes that are in ListKeepInside, as object shapes;
2837 for (ind = 0; ind < ListKeepInside.length(); ind++) {
2839 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListKeepInside[ind] );
2840 TopoDS_Shape Shape = GetTopoShape(aShape);
2841 if(Shape.IsNull() ) {
2842 //MESSAGE ( "In Partition a Keep Inside shape is null" );
2843 THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM);
2845 if (!ToolsMap.Contains( Shape ) &&
2846 ShapesMap.Add( Shape ))
2850 // add shapes that are in ListRemoveInside, as object shapes;
2851 for (ind = 0; ind < ListRemoveInside.length(); ind++) {
2853 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListRemoveInside[ind] );
2854 TopoDS_Shape Shape = GetTopoShape(aShape);
2855 if(Shape.IsNull() ) {
2856 //MESSAGE ( "In Partition a Remove Inside shape is null" );
2857 THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM);
2859 if (!ToolsMap.Contains( Shape ) &&
2860 ShapesMap.Add( Shape ) )
2864 PS.Compute ((TopAbs_ShapeEnum) Limit);
2866 // suppress result outside of shapes in KInsideMap
2867 for (ind = 0; ind < ListKeepInside.length(); ind++) {
2868 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListKeepInside[ind] );
2869 TopoDS_Shape Shape = GetTopoShape(aShape);
2870 PS.KeepShapesInside( Shape );
2873 // suppress result inside of shapes in RInsideMap
2874 for (ind = 0; ind < ListRemoveInside.length(); ind++) {
2876 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListRemoveInside[ind] );
2877 TopoDS_Shape Shape = GetTopoShape(aShape);
2878 PS.RemoveShapesInside( Shape );
2883 if( !IsValid(tds) ) {
2884 //MESSAGE ( "In Partition: non valid shape result" );
2885 THROW_SALOME_CORBA_EXCEPTION("Partition aborted : non valid shape result", SALOME::BAD_PARAM);
2888 catch (Standard_Failure) {
2889 //MESSAGE ( "In Partition: Exception catched in GEOM_Gen_i::Partition()" );
2890 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::Partition", SALOME::BAD_PARAM);
2893 aResult = CreateObject(tds) ;
2895 /* add attributs S and mystr in a new label */
2896 GEOMDS_Commands GC(myCurrentOCAFDoc->Main());
2897 TDF_Label Lab = GC.AddShape(tds, aResult->Name() );
2898 TCollection_AsciiString entry;
2899 TDF_Tool::Entry(Lab,entry);
2900 aResult->ShapeId( entry.ToCString() ) ;
2904 /* Create a new label */
2905 TDF_Label NewLab = Lab.NewChild();
2906 TCollection_ExtendedString Value("Arguments");
2907 TDataStd_Name::Set(NewLab,Value);
2910 for (unsigned int ind = 0; ind < ListShapes.length(); ind++) {
2911 TDF_Label NewLab1 = NewLab.NewChild();
2913 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[ind] );
2914 Standard_CString anEntry = aShape->ShapeId();
2916 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), anEntry, RefLab);
2917 TDF_Reference::Set(NewLab1,RefLab);
2920 for (unsigned int ind = 0; ind < ListTools.length(); ind++) {
2921 TDF_Label NewLab1 = NewLab.NewChild();
2923 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListTools[ind] );
2924 Standard_CString anEntry = aShape->ShapeId();
2926 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), anEntry, RefLab);
2927 TDF_Reference::Set(NewLab1,RefLab);
2930 for (unsigned int ind = 0; ind < ListKeepInside.length(); ind++) {
2931 TDF_Label NewLab1 = NewLab.NewChild();
2933 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListKeepInside[ind] );
2934 Standard_CString anEntry = aShape->ShapeId();
2936 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), anEntry, RefLab);
2937 TDF_Reference::Set(NewLab1,RefLab);
2940 for (unsigned int ind = 0; ind < ListRemoveInside.length(); ind++) {
2941 TDF_Label NewLab1 = NewLab.NewChild();
2943 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListRemoveInside[ind] );
2944 Standard_CString anEntry = aShape->ShapeId();
2946 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), anEntry, RefLab);
2947 TDF_Reference::Set(NewLab1,RefLab);
2955 //==================================================================================
2956 // function : MakeFilling()
2957 // purpose : Create a surface from section curves filling
2958 //==================================================================================
2959 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFilling(GEOM::GEOM_Shape_ptr myShape,
2960 CORBA::Short mindeg,
2961 CORBA::Short maxdeg,
2962 CORBA::Double tol3d,
2963 CORBA::Double tol2d,
2964 CORBA::Short nbiter)
2965 throw (SALOME::SALOME_Exception)
2967 GEOM::GEOM_Shape_var result ;
2969 TopoDS_Shape aShape = GetTopoShape(myShape) ;
2970 if( aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND ) {
2971 THROW_SALOME_CORBA_EXCEPTION("MakeFilling aborted : null shape or not a compound", SALOME::BAD_PARAM);
2975 /* we verify the contents of the shape */
2976 TopExp_Explorer Ex ;
2977 TopoDS_Shape Scurrent ;
2978 Standard_Real First, Last ;
2979 Handle(Geom_Curve) C ;
2980 GeomFill_SectionGenerator Section ;
2982 Standard_Integer i = 0 ;
2983 for(Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
2984 Scurrent = Ex.Current() ;
2985 if( Scurrent.IsNull() || Scurrent.ShapeType() != TopAbs_EDGE) {
2986 THROW_SALOME_CORBA_EXCEPTION("Initial shape doesn't contain only edges !", SALOME::BAD_PARAM);
2988 C = BRep_Tool::Curve(TopoDS::Edge(Scurrent), First, Last);
2989 C = new Geom_TrimmedCurve(C, First, Last);
2990 Section.AddCurve(C) ;
2994 /* a 'tolerance' is used to compare 2 knots : see GeomFill_Generator.cdl */
2995 /* We set 'tolerance' = tol3d */
2996 // Section.Perform( tol3d ) ; NRI */
2997 Section.Perform( Precision::Confusion() ) ;
2998 Handle(GeomFill_Line) Line = new GeomFill_Line(i) ;
3000 GeomFill_AppSurf App(mindeg, maxdeg, tol3d, tol2d, nbiter) ; /* user parameters */
3001 App.Perform(Line, Section) ;
3003 if (!App.IsDone()) {
3004 THROW_SALOME_CORBA_EXCEPTION("Filling aborted : non valid shape result", SALOME::BAD_PARAM);
3006 Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
3007 App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
3008 Handle(Geom_BSplineSurface) GBS = new Geom_BSplineSurface(App.SurfPoles(),
3017 if( GBS.IsNull() ) {
3018 THROW_SALOME_CORBA_EXCEPTION("Make Filling aborted", SALOME::BAD_PARAM);
3020 tds = BRepBuilderAPI_MakeFace(GBS) ;
3022 catch(Standard_Failure) {
3023 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeFilling", SALOME::BAD_PARAM);
3026 /* We test the validity of resulting shape */
3027 if( !IsValid(tds) ) {
3028 THROW_SALOME_CORBA_EXCEPTION("Filling aborted : non valid shape result", SALOME::BAD_PARAM);
3031 result = CreateObject(tds) ;
3032 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3039 //=================================================================================
3040 // function : MakeGlueFaces()
3042 //=================================================================================
3044 TopoDS_Face GEOM_Gen_i::FindSameFace(const TopoDS_Shape& aShape,
3045 const TopoDS_Face& F,
3049 bool isSame = false;
3050 for (TopExp_Explorer exf(aShape,TopAbs_FACE); exf.More(); exf.Next())
3052 //MESSAGE("--- test a face");
3054 aFace = TopoDS::Face(exf.Current());
3055 TopTools_ListOfShape liste1;
3056 TopTools_ListOfShape liste2;
3057 for (TopExp_Explorer exp(aFace,TopAbs_VERTEX); exp.More(); exp.Next())
3059 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
3062 for (TopExp_Explorer exp(F,TopAbs_VERTEX); exp.More(); exp.Next())
3064 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
3068 if (liste1.Extent() == liste2.Extent())
3070 TopTools_ListIteratorOfListOfShape it1(liste1);
3072 for (; it1.More(); it1.Next())
3074 bool foundSamePoint = false;
3075 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(it1.Value()));
3076 TopTools_ListIteratorOfListOfShape it2(liste2);
3077 for (it2; it2.More(); it2.Next())
3079 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(it2.Value()));
3080 double d = P1.Distance(P2);
3084 //MESSAGE(" found Same Point : "<<nbFound<<" - "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z());
3085 foundSamePoint = true;
3089 isSame = isSame && foundSamePoint;
3090 if (! isSame) break; // a vertex does not correspond : not same face
3095 //MESSAGE(" --- Found Same Face");
3096 break; // a face corresponding to F is found
3099 if (! isSame) aFace.Nullify(); // return null face
3103 TopoDS_Edge GEOM_Gen_i::FindSameEdge(const TopoDS_Face& nf,
3107 TopoDS_Face newFace = TopoDS::Face(nf.Oriented(TopAbs_REVERSED));
3108 TopoDS_Vertex VFirst, VLast;
3109 TopExp::Vertices(Eold, VFirst, VLast);
3110 gp_Pnt Pf = BRep_Tool::Pnt(VFirst);
3111 gp_Pnt Pl = BRep_Tool::Pnt(VLast);
3113 for (TopExp_Explorer ee(newFace,TopAbs_EDGE); ee.More(); ee.Next())
3115 const TopoDS_Edge& E = TopoDS::Edge(ee.Current());
3116 TopoDS_Vertex VFn, VLn;
3117 TopExp::Vertices(E, VFn, VLn);
3118 gp_Pnt Pfn = BRep_Tool::Pnt(VFn);
3119 gp_Pnt Pln = BRep_Tool::Pnt(VLn);
3120 double dff = Pf.Distance(Pfn);
3121 double dfl = Pf.Distance(Pln);
3122 double dlf = Pl.Distance(Pfn);
3123 double dll = Pl.Distance(Pln);
3124 if ((dff < tol3d) && (dll <tol3d))
3126 //MESSAGE("--- edge forward " <<Pf.X()<<" "<<Pf.Y()<<" "<<Pf.Z()<<" "<<Pl.X()<<" "<<Pl.Y()<<" "<<Pl.Z());
3127 Enew = TopoDS::Edge(E.Oriented(TopAbs_FORWARD));
3128 Eold = TopoDS::Edge(Eold.Oriented(TopAbs_FORWARD));
3131 if ((dfl < tol3d) && (dlf <tol3d))
3133 //MESSAGE("--- edge reversed " <<Pf.X()<<" "<<Pf.Y()<<" "<<Pf.Z()<<" "<<Pl.X()<<" "<<Pl.Y()<<" "<<Pl.Z());
3134 Enew = TopoDS::Edge(E.Oriented(TopAbs_REVERSED));
3135 Eold = TopoDS::Edge(Eold.Oriented(TopAbs_FORWARD));
3142 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeGlueFaces(GEOM::GEOM_Shape_ptr myShape,
3144 throw (SALOME::SALOME_Exception)
3147 // prendre un premier shell dans la liste des shells
3148 // initialiser un compshell avec ce shell
3149 // tant qu'il reste des shells dans la liste
3150 // chercher un shell qui a des faces en commun avec le compshell
3151 // creer un BRepTools_Quilt
3152 // recenser les faces communes issues du compshell, les ajouter au quilt
3153 // recenser les faces restantes du shell a inclure, les ajouter au quilt
3154 // recenser les edges en double, a remplacer
3155 // pour chaque paire d'edge
3156 // tester l'orientation relative des aretes
3157 // bind dans le quilt de Eold.Forward et Enew.Forward (ou reverse)
3158 // recuperer le nouveau shell
3159 // l'incorporer dans le compshell
3160 // appliquer BRepTools_SameParameter au compshell
3161 // (rendre parametres 2D des edges identiques aux parametres 3D)
3163 GEOM::GEOM_Shape_var result ;
3165 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3168 bu.MakeCompound(C); // empty compound;
3169 TopTools_ListOfShape shellList;
3170 for (TopExp_Explorer exp(aShape,TopAbs_SHELL); exp.More(); exp.Next())
3172 const TopoDS_Shell& S = TopoDS::Shell(exp.Current());
3173 shellList.Append(S);
3175 TopTools_ListIteratorOfListOfShape its(shellList);
3178 THROW_SALOME_CORBA_EXCEPTION("glue aborted : no shell in shape", SALOME::BAD_PARAM);
3180 TopoDS_Shell S = TopoDS::Shell(its.Value());
3181 bu.Add(C, S); // add first shell to compound
3182 shellList.Remove(its);
3183 its.Initialize(shellList);
3184 bool shellAdded = true;
3185 while ((shellList.Extent() > 0) && shellAdded)
3187 //MESSAGE("more shells : "<< shellList.Extent());
3189 its.Initialize(shellList);
3190 for(; its.More(); its.Next())
3192 //MESSAGE("one more shell to try");
3193 TopTools_ListOfShape newFaces; // common faces from new compound
3194 TopTools_ListOfShape oldFaces; // common faces from shell to add
3195 TopTools_ListOfShape addFaces; // not common faces from shell to add
3196 TopTools_ListOfShape newEdges; // common edges from new compound
3197 TopTools_ListOfShape oldEdges; // common edges from face to add
3198 TopoDS_Compound CFN;
3199 TopoDS_Compound CFO;
3200 bu.MakeCompound(CFN); // empty compound for new faces
3201 bu.MakeCompound(CFO); // empty compound for old faces
3202 S = TopoDS::Shell(its.Value());
3203 for (TopExp_Explorer exp(S,TopAbs_FACE); exp.More(); exp.Next())
3205 //MESSAGE("--- try to find corresponding face in new compound");
3206 TopoDS_Face F = TopoDS::Face(exp.Current());
3207 TopoDS_Face newFace = FindSameFace(C,F,tol3d);
3208 if (! newFace.IsNull())
3210 //MESSAGE("--- face found");
3211 newFaces.Append(newFace);
3212 bu.Add(CFN, newFace); // common faces from new compound
3214 for (TopExp_Explorer ee(F,TopAbs_EDGE);ee.More();ee.Next())
3216 //MESSAGE("--- find edge pair");
3217 TopoDS_Edge Eold = TopoDS::Edge(ee.Current());
3218 const TopoDS_Edge& Enew = FindSameEdge(newFace, Eold, tol3d);
3219 oldEdges.Append(Eold);
3220 newEdges.Append(Enew);
3227 bu.Add(CFO, F); // not common faces from shell to add
3230 if ( !newFaces.IsEmpty())
3232 //MESSAGE("--- some faces found ---");
3234 BRepTools_Quilt glue;
3236 TopTools_ListIteratorOfListOfShape ito(oldEdges);
3237 TopTools_ListIteratorOfListOfShape itn(newEdges);
3238 for (; ito.More(); ito.Next())
3240 //MESSAGE("--- bind");
3241 glue.Bind(TopoDS::Edge(ito.Value()), TopoDS::Edge(itn.Value()));
3245 TopoDS_Compound newc = TopoDS::Compound(glue.Shells());
3246 for (TopExp_Explorer exs(newc,TopAbs_SHELL); exs.More(); exs.Next())
3248 TopoDS_Shell NS = TopoDS::Shell(exs.Current());
3251 shellList.Remove(its);
3252 //MESSAGE("--- remove shell from list");
3257 //MESSAGE("---" << shellList.Extent() << " " << shellAdded);
3259 TopExp_Explorer exp(C,TopAbs_SHELL);
3260 Standard_Integer ish=0;
3261 TopoDS_Compound Res;
3264 B.MakeCompound(Res);
3265 TopoDS_Shape theShape;
3267 for (; exp.More(); exp.Next())
3269 TopoDS_Shape Sh = exp.Current();
3272 BRepClass3d_SolidClassifier SC(Sol);
3273 SC.PerformInfinitePoint(1.E-6); // cf. BRepFill_Confusion() - BRepFill_Evolved.cxx
3274 if (SC.State() == TopAbs_IN)
3277 B.Add(Sol,Sh.Reversed());
3282 if (ish == 1) { theShape = Sol;}
3283 else { theShape = Res;}
3285 BRepLib::SameParameter(theShape, 1.E-5, Standard_True);
3287 result = CreateObject(tds);
3288 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3293 //=================================================================================
3294 // function : MakeSewing()
3296 //=================================================================================
3297 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewing( const GEOM::GEOM_Gen::ListOfIOR& ListShapes,
3298 CORBA::Double precision )
3299 throw (SALOME::SALOME_Exception)
3301 GEOM::GEOM_Shape_var result ;
3303 BRepOffsetAPI_Sewing aMethod ;
3306 /* default OCC is 1.0e-06 */
3307 aMethod.Init(precision, Standard_False);
3308 for ( unsigned int i = 0; i < ListShapes.length(); i++) {
3309 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[i] );
3310 TopoDS_Shape Shape = GetTopoShape(aShape) ;
3311 if( Shape.IsNull() ) {
3312 THROW_SALOME_CORBA_EXCEPTION("MakeSewing aborted : null shape during operation", SALOME::BAD_PARAM);
3314 aMethod.Add(Shape) ;
3318 tds = aMethod.SewedShape() ;
3319 if( !IsValid(tds) ) {
3320 THROW_SALOME_CORBA_EXCEPTION("Make Sewing aborted : non valid shape", SALOME::BAD_PARAM);
3322 if( tds.IsNull() ) {
3323 THROW_SALOME_CORBA_EXCEPTION("Make Sewing aborted : null shape", SALOME::BAD_PARAM);
3326 catch (Standard_Failure) {
3327 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeSewing", SALOME::BAD_PARAM);
3330 result = CreateObject(tds);
3331 InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
3335 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewingShape( GEOM::GEOM_Shape_ptr aShape,
3336 CORBA::Double precision )
3337 throw (SALOME::SALOME_Exception)
3339 GEOM::GEOM_Shape_var result ;
3340 TopoDS_Shape tds, S ;
3341 BRepOffsetAPI_Sewing aMethod ;
3344 S = GetTopoShape(aShape) ;
3346 THROW_SALOME_CORBA_EXCEPTION("In Sewing a Shape is null", SALOME::BAD_PARAM);
3349 /* default OCC is 1.0e-06 */
3350 aMethod.Init(precision, Standard_False);
3351 for ( TopExp_Explorer exp( S, TopAbs_FACE); exp.More(); exp.Next() ) {
3352 const TopoDS_Face& F = TopoDS::Face(exp.Current());
3357 tds = aMethod.SewedShape() ;
3358 if( !IsValid(tds) ) {
3359 THROW_SALOME_CORBA_EXCEPTION("Make Sewing aborted : non valid shape", SALOME::BAD_PARAM);
3362 catch (Standard_Failure) {
3363 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeSewing", SALOME::BAD_PARAM);
3366 result = CreateObject(tds);
3367 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3368 result->ShapeId(entry) ;
3372 //==================================================================================
3373 // function : OrientationChange()
3374 // purpose : Change the orientation of a new shape
3375 // : TopAbs_FORWARD < -- > TopAbs_REVERSED
3377 // : WARNING : for the moment we make a new shape !
3378 //==================================================================================
3379 GEOM::GEOM_Shape_ptr GEOM_Gen_i::OrientationChange(GEOM::GEOM_Shape_ptr aShape)
3380 throw (SALOME::SALOME_Exception)
3382 GEOM::GEOM_Shape_var result ;
3383 BRep_Builder aBuilder;
3385 TopoDS_Shape shape = GetTopoShape(aShape) ;
3386 if( shape.IsNull() ) {
3387 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
3390 BRepBuilderAPI_Copy Copy(shape);
3391 if( Copy.IsDone() ) {
3392 TopoDS_Shape tds = Copy.Shape();
3393 if( tds.IsNull() ) {
3394 THROW_SALOME_CORBA_EXCEPTION("Orientation aborted : null shape", SALOME::BAD_PARAM);
3397 if( tds.Orientation() == TopAbs_FORWARD)
3398 tds.Orientation(TopAbs_REVERSED) ;
3400 tds.Orientation(TopAbs_FORWARD) ;
3402 result = CreateObject(tds);
3403 InsertInLabelOneArgument(shape, aShape, tds, result, myCurrentOCAFDoc) ;
3409 //==================================================================================
3410 // function : GetReferencedObjects()
3412 //==================================================================================
3413 GEOM::GEOM_Gen::ListOfIOR* GEOM_Gen_i::GetReferencedObjects(GEOM::GEOM_Shape_ptr shape)
3415 GEOM::GEOM_Gen::ListOfIOR_var aList = new GEOM::GEOM_Gen::ListOfIOR;
3418 if (shape->_is_nil()) return aList._retn();
3420 Standard_CString entry = shape->ShapeId();
3422 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), entry, Lab);
3424 Handle(TDataStd_Name) Att;
3425 Lab.FindAttribute(TDataStd_Name::GetID(),Att);
3427 TDF_ChildIterator ChildIterator(Lab);
3428 if (ChildIterator.More()) {
3429 TDF_Label L = ChildIterator.Value();
3430 Handle(TDataStd_Name) Att;
3431 L.FindAttribute(TDataStd_Name::GetID(),Att);
3432 if (Att->Get().IsEqual(TCollection_ExtendedString("Arguments")) ) {
3434 TDF_ChildIterator ChildIterator1(L);
3437 while (ChildIterator1.More()) {
3438 TDF_Label L = ChildIterator1.Value();
3440 Handle(TDF_Reference) Ref;
3441 if (L.FindAttribute(TDF_Reference::GetID(),Ref)) {
3444 ChildIterator1.Next();
3448 TDF_ChildIterator ChildIterator2(L);
3449 while (ChildIterator2.More()) {
3450 TDF_Label L = ChildIterator2.Value();
3451 Handle(TDF_Reference) Ref;
3452 if (L.FindAttribute(TDF_Reference::GetID(),Ref)) {
3453 TDF_Label L = Ref->Get();
3455 Handle(TDataStd_Name) Att;
3456 L.FindAttribute(TDataStd_Name::GetID(),Att);
3457 TCollection_AsciiString nameIOR (Att->Get()) ;
3458 aList[i] = strdup( nameIOR.ToCString() );
3462 ChildIterator2.Next();
3466 return aList._retn();
3469 //==================================================================================
3470 // function : GetObjects()
3472 //==================================================================================
3473 GEOM::GEOM_Gen::ListOfIOR* GEOM_Gen_i::GetObjects(GEOM::GEOM_Shape_ptr shape)
3475 GEOM::GEOM_Gen::ListOfIOR_var aList = new GEOM::GEOM_Gen::ListOfIOR;
3478 Standard_CString entry = shape->ShapeId();
3480 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), entry, Lab);
3482 Handle(TDataStd_Name) Att;
3483 Lab.FindAttribute(TDataStd_Name::GetID(),Att);
3485 TDF_ChildIterator ChildIterator(Lab);
3487 while (ChildIterator.More()) {
3488 TDF_Label L = ChildIterator.Value();
3489 Handle(TDataStd_Name) Att;
3490 L.FindAttribute(TDataStd_Name::GetID(),Att);
3492 if (!Att->Get().IsEqual(TCollection_ExtendedString("Arguments")) ) {
3495 ChildIterator.Next();
3500 TDF_ChildIterator ChildIterator1(Lab);
3501 while (ChildIterator1.More()) {
3502 TDF_Label L = ChildIterator1.Value();
3503 Handle(TDataStd_Name) Att;
3504 L.FindAttribute(TDataStd_Name::GetID(),Att);
3506 if (!Att->Get().IsEqual(TCollection_ExtendedString("Arguments")) ) {
3507 TCollection_AsciiString nameIOR (Att->Get());
3508 aList[i] = strdup( nameIOR.ToCString() );
3511 ChildIterator1.Next();
3513 return aList._retn();
3517 //==================================================================================
3518 // function : Import
3519 // purpose : Import shape from a BREP file
3520 //==================================================================================
3521 GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportBREP(const char* filename)
3522 throw (SALOME::SALOME_Exception)
3525 GEOM::GEOM_Shape_var result ;
3528 BRep_Builder aBuilder;
3529 BRepTools::Read(tds, strdup(filename), aBuilder) ;
3531 THROW_SALOME_CORBA_EXCEPTION("Import BRep aborted", SALOME::BAD_PARAM);
3534 catch(Standard_Failure) {
3535 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportBREP", SALOME::BAD_PARAM);
3538 result = CreateObject(tds) ;
3539 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3540 result->ShapeId(entry);
3545 //================================================================================
3546 // function : MakePlane()
3547 // purpose : Make a plane topology (non infinite)
3548 //================================================================================
3549 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePlane(const GEOM::PointStruct& pstruct,
3550 const GEOM::DirStruct& dstruct,
3551 CORBA::Double trimsize)
3552 throw (SALOME::SALOME_Exception)
3554 GEOM::GEOM_Shape_var result ;
3558 gp_Pnt aPoint(pstruct.x, pstruct.y, pstruct.z) ;
3559 gp_Dir aDirection(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
3560 /* we make a trimmed plane */
3561 gp_Pln gplane(aPoint, aDirection) ;
3562 tds = BRepBuilderAPI_MakeFace(gplane, -trimsize, +trimsize, -trimsize, +trimsize) ;
3564 catch(Standard_Failure) {
3565 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePlane", SALOME::BAD_PARAM);
3569 THROW_SALOME_CORBA_EXCEPTION("Make Plane aborted : null shape", SALOME::BAD_PARAM);
3572 result = CreateObject(tds) ;
3573 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3574 result->ShapeId(entry);
3578 //=================================================================================
3579 // function : MakeVertex()
3580 // purpose : Create a Vertex topology.
3581 //=================================================================================
3582 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeVertex(CORBA::Double x,
3585 throw (SALOME::SALOME_Exception)
3588 GEOM::GEOM_Shape_var result ;
3590 TopoDS_Shape tds = BRepBuilderAPI_MakeVertex(P).Shape();
3592 THROW_SALOME_CORBA_EXCEPTION("Make Vertex/Point aborted", SALOME::BAD_PARAM);
3594 result = CreateObject(tds) ;
3595 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3596 result->ShapeId(entry);
3601 //=================================================================================
3602 // function : MakeFace()
3604 //=================================================================================
3605 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFace( GEOM::GEOM_Shape_ptr wire,
3606 CORBA::Boolean wantplanarface )
3607 throw (SALOME::SALOME_Exception)
3609 GEOM::GEOM_Shape_var result ;
3610 TopoDS_Shape aShape;
3614 aShape = GetTopoShape(wire) ;
3615 if( aShape.IsNull() || aShape.ShapeType() != TopAbs_WIRE ) {
3616 THROW_SALOME_CORBA_EXCEPTION("MakeFace aborted : null or inappropriate shape", SALOME::BAD_PARAM);
3618 TopoDS_Wire W = TopoDS::Wire(aShape) ;
3619 tds = BRepBuilderAPI_MakeFace(W, wantplanarface).Shape() ;
3620 if( !tds.IsNull() ) {
3621 result = CreateObject(tds) ;
3622 InsertInLabelOneArgument(aShape, wire, tds, result, myCurrentOCAFDoc) ;
3625 THROW_SALOME_CORBA_EXCEPTION("Null result in GEOM_Gen_i::MakeFace", SALOME::BAD_PARAM);
3628 catch (Standard_Failure) {
3629 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeFace", SALOME::BAD_PARAM);
3635 //================================================================================
3636 // function : MakeLine
3637 // purpose : Make a Line topology
3638 //================================================================================
3639 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeLine(const GEOM::PointStruct& pstruct,
3640 const GEOM::DirStruct& dstruct)
3641 throw (SALOME::SALOME_Exception)
3643 GEOM::GEOM_Shape_var result ;
3644 gp_Pnt P1(pstruct.x, pstruct.y, pstruct.z);
3645 gp_Pnt P2(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
3649 tds = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
3651 catch(Standard_Failure) {
3652 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeLine", SALOME::BAD_PARAM);
3655 if ( tds.IsNull() ) {
3656 THROW_SALOME_CORBA_EXCEPTION("Make Line aborted : null shape", SALOME::BAD_PARAM);
3659 result = CreateObject(tds) ;
3660 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3661 result->ShapeId(entry);
3667 //================================================================================
3668 // function : MakeVector()
3669 // purpose : Make a vector
3670 //================================================================================
3671 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeVector(const GEOM::PointStruct& pstruct1,
3672 const GEOM::PointStruct& pstruct2)
3673 throw (SALOME::SALOME_Exception)
3675 GEOM::GEOM_Shape_var result ;
3679 gp_Pnt P1(pstruct1.x, pstruct1.y, pstruct1.z);
3680 gp_Pnt P2(pstruct2.x, pstruct2.y, pstruct2.z) ;
3681 tds = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
3683 catch(Standard_Failure) {
3684 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeVector", SALOME::BAD_PARAM);
3687 if ( tds.IsNull() ) {
3688 THROW_SALOME_CORBA_EXCEPTION("Make Vector aborted : null shape", SALOME::BAD_PARAM);
3691 result = CreateObject(tds) ;
3692 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3693 result->ShapeId(entry);
3699 //================================================================================
3700 // function : MakeCircle()
3702 //================================================================================
3703 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCircle(const GEOM::PointStruct& pstruct,
3704 const GEOM::DirStruct& dstruct,
3705 CORBA::Double radius)
3706 throw (SALOME::SALOME_Exception)
3708 GEOM::GEOM_Shape_var result;
3712 gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ;
3713 gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
3715 gp_Circ circ( axis, radius);
3716 BRepBuilderAPI_MakeEdge MakeEdge( circ );
3717 tds = MakeEdge.Edge();
3719 catch(Standard_Failure) {
3720 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeCircle", SALOME::BAD_PARAM);
3723 THROW_SALOME_CORBA_EXCEPTION("Make Circle aborted", SALOME::BAD_PARAM);
3725 result = CreateObject(tds);
3726 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3727 result->ShapeId(entry);
3731 //================================================================================
3732 // function : MakeArc()
3733 // purpose : make an arc of circle from pInit to pEnd and passing on pCircle
3734 //================================================================================
3735 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeArc(const GEOM::PointStruct& pInit,
3736 const GEOM::PointStruct& pCircle,
3737 const GEOM::PointStruct& pEnd)
3738 throw (SALOME::SALOME_Exception)
3740 GEOM::GEOM_Shape_var result;
3742 gp_Pnt pI(pInit.x, pInit.y, pInit.z) ;
3743 gp_Pnt pC(pCircle.x, pCircle.y, pCircle.z) ;
3744 gp_Pnt pE(pEnd.x, pEnd.y, pEnd.z) ;
3746 GC_MakeArcOfCircle arc( pI, pC, pE ) ;
3747 if( !arc.IsDone() ) {
3748 THROW_SALOME_CORBA_EXCEPTION("Arc not done", SALOME::BAD_PARAM);
3750 BRepBuilderAPI_MakeEdge MakeEdge( arc );
3751 TopoDS_Shape tds = MakeEdge.Edge();
3753 THROW_SALOME_CORBA_EXCEPTION("Null result : arc not done", SALOME::BAD_PARAM);
3756 result = CreateObject(tds);
3757 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3758 result->ShapeId(entry);
3761 catch(Standard_Failure) {
3762 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeArc", SALOME::BAD_PARAM);
3769 //=================================================================================
3770 // function : MakeTranslation()
3771 // purpose : Translate a 3D shape
3772 //=================================================================================
3773 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeTranslation( GEOM::GEOM_Shape_ptr myShape,
3777 throw (SALOME::SALOME_Exception)
3779 GEOM::GEOM_Shape_var result ;
3780 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3781 if( aShape.IsNull() ) {
3782 THROW_SALOME_CORBA_EXCEPTION("Translation aborted : null shape", SALOME::BAD_PARAM);
3784 gp_Vec theVector(x,y,z) ;
3785 gp_Trsf theTransformation ;
3786 theTransformation.SetTranslation(theVector) ;
3787 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
3788 TopoDS_Shape tds = myBRepTransformation.Shape() ;
3790 result = CreateObject(tds) ;
3791 if( CORBA::is_nil(result) ) {
3792 THROW_SALOME_CORBA_EXCEPTION("Translation aborted : null result", SALOME::BAD_PARAM);
3794 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3799 //=================================================================================
3800 // function : MakeMultiTranslation1D()
3801 // purpose : Multi-Translate a 3D shape
3802 //=================================================================================
3803 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiTranslation1D( GEOM::GEOM_Shape_ptr myShape,
3804 const GEOM::DirStruct& dir,
3806 CORBA::Short nbtimes )
3807 throw (SALOME::SALOME_Exception)
3809 GEOM::GEOM_Shape_var result ;
3812 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3813 if( aShape.IsNull() )
3814 THROW_SALOME_CORBA_EXCEPTION("MakeMultiTranslation1D aborted : null shape", SALOME::BAD_PARAM);
3819 gp_Trsf theTransformation ;
3821 gp_Vec Vec( dir.PS.x, dir.PS.y, dir.PS.z ) ;
3823 TopoDS_Compound compound;
3825 B.MakeCompound( compound );
3827 for ( i = 0; i < nbtimes; i++ ) {
3828 DX = i * step * Vec.X() ;
3829 DY = i * step * Vec.Y() ;
3830 DZ = i * step * Vec.Z() ;
3831 myVec.SetCoord( DX, DY, DZ ) ;
3832 theTransformation.SetTranslation(myVec) ;
3833 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
3834 B.Add( compound, myBRepTransformation.Shape() );
3837 result = CreateObject(tds) ;
3839 catch (Standard_Failure) {
3840 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMultiTranslation1D", SALOME::BAD_PARAM);
3843 if( CORBA::is_nil(result) ) {
3844 THROW_SALOME_CORBA_EXCEPTION("MakeMultiTranslation1D aborted : null result", SALOME::BAD_PARAM);
3846 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3851 //=================================================================================
3852 // function : MakeMultiTranslation2D()
3853 // purpose : Multi-Translate a 3D shape
3854 //=================================================================================
3855 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiTranslation2D( GEOM::GEOM_Shape_ptr myShape,
3856 const GEOM::DirStruct& dir1,
3857 CORBA::Double step1,
3858 CORBA::Short nbtimes1,
3859 const GEOM::DirStruct& dir2,
3860 CORBA::Double step2,
3861 CORBA::Short nbtimes2 )
3862 throw (SALOME::SALOME_Exception)
3864 GEOM::GEOM_Shape_var result ;
3867 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3868 if( aShape.IsNull() ) {
3869 THROW_SALOME_CORBA_EXCEPTION("MakeMultiTranslation2D aborted : null shape", SALOME::BAD_PARAM);
3875 gp_Trsf theTransformation ;
3877 gp_Vec Vec1( dir1.PS.x, dir1.PS.y, dir1.PS.z ) ;
3879 gp_Vec Vec2( dir2.PS.x, dir2.PS.y, dir2.PS.z ) ;
3881 TopoDS_Compound compound;
3883 B.MakeCompound( compound );
3885 for ( i = 0; i < nbtimes1; i++ ) {
3886 for ( j = 0; j < nbtimes2; j++ ) {
3887 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X() ;
3888 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y() ;
3889 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z() ;
3890 myVec.SetCoord( DX, DY, DZ ) ;
3891 theTransformation.SetTranslation(myVec) ;
3892 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
3893 B.Add( compound, myBRepTransformation.Shape() );
3897 result = CreateObject(tds) ;
3899 catch(Standard_Failure) {
3900 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMultiTranslation2D", SALOME::BAD_PARAM);
3903 if( CORBA::is_nil(result) ) {
3904 THROW_SALOME_CORBA_EXCEPTION("MakeMultiTranslation2D aborted : null result", SALOME::BAD_PARAM);
3906 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3911 //=================================================================================
3912 // function : MakeMultiRotation1D()
3913 // purpose : Multi-Rotate a 3D shape
3914 //=================================================================================
3915 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiRotation1D( GEOM::GEOM_Shape_ptr myShape,
3916 const GEOM::DirStruct& dir,
3917 const GEOM::PointStruct& loc,
3918 CORBA::Short nbtimes)
3919 throw (SALOME::SALOME_Exception)
3921 GEOM::GEOM_Shape_var result ;
3923 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3924 if( aShape.IsNull() ) {
3925 THROW_SALOME_CORBA_EXCEPTION("MakeMultiRotation1D aborted : null shape", SALOME::BAD_PARAM);
3931 gp_Pnt P(loc.x, loc.y, loc.z) ;
3932 gp_Dir D(dir.PS.x, dir.PS.y, dir.PS.z) ;
3935 double angle = 360.0/nbtimes ;
3936 gp_Trsf theTransformation ;
3937 TopoDS_Compound compound;
3939 B.MakeCompound( compound );
3941 for ( i = 0; i < nbtimes; i++ ) {
3942 theTransformation.SetRotation(AX1, i*angle*PI180) ;
3943 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
3944 B.Add( compound, myBRepTransformation.Shape() );
3947 result = CreateObject(tds) ;
3949 catch(Standard_Failure) {
3950 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMultiRotation1D", SALOME::BAD_PARAM);
3953 if( CORBA::is_nil(result) ) {
3954 THROW_SALOME_CORBA_EXCEPTION("MakeMultiRotation1D aborted : null result", SALOME::BAD_PARAM);
3956 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3961 //=================================================================================
3962 // function : MakeMultiRotation2D()
3963 // purpose : Multi-Rotate a 3D shape
3964 //=================================================================================
3965 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiRotation2D( GEOM::GEOM_Shape_ptr myShape,
3966 const GEOM::DirStruct& dir,
3967 const GEOM::PointStruct& loc,
3969 CORBA::Short nbtimes1,
3971 CORBA::Short nbtimes2 )
3972 throw (SALOME::SALOME_Exception)
3974 GEOM::GEOM_Shape_var result ;
3976 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3977 if( aShape.IsNull() ) {
3978 THROW_SALOME_CORBA_EXCEPTION("MakeMultiRotation2D aborted : null shape", SALOME::BAD_PARAM);
3985 gp_Pnt P(loc.x, loc.y, loc.z) ;
3986 gp_Dir D(dir.PS.x, dir.PS.y, dir.PS.z) ;
3988 gp_Trsf theTransformation1 ;
3989 gp_Trsf theTransformation2 ;
3991 GProp_GProps System ;
3993 if ( aShape.ShapeType() == TopAbs_VERTEX) {
3994 P1 = BRep_Tool::Pnt(TopoDS::Vertex( aShape ));
3996 else if ( aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE ) {
3997 BRepGProp::LinearProperties(aShape, System);
3998 P1 = System.CentreOfMass() ;
4000 else if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL ) {
4001 BRepGProp::SurfaceProperties(aShape, System);
4002 P1 = System.CentreOfMass() ;
4005 BRepGProp::VolumeProperties(aShape, System);
4006 P1 = System.CentreOfMass() ;
4009 Handle(Geom_Line) Line = new Geom_Line(AX1);
4010 gp_Pnt P2 = GeomAPI_ProjectPointOnCurve( P1, Line ) ;
4012 if ( P1.IsEqual(P2, Precision::Confusion() ) )
4013 THROW_SALOME_CORBA_EXCEPTION("Points are confused", SALOME::BAD_PARAM);
4015 gp_Vec Vec(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()) ;
4019 TopoDS_Compound compound;
4021 B.MakeCompound( compound );
4023 for ( i = 0; i < nbtimes2; i++ ) {
4024 for ( j = 0; j < nbtimes1; j++ ) {
4025 DX = i * step * Vec.X() ;
4026 DY = i * step * Vec.Y() ;
4027 DZ = i * step * Vec.Z() ;
4028 myVec.SetCoord( DX, DY, DZ ) ;
4029 theTransformation1.SetTranslation(myVec) ;
4030 theTransformation2.SetRotation(AX1, j*ang*PI180) ;
4031 BRepBuilderAPI_Transform myBRepTransformation1(aShape, theTransformation1, Standard_False) ;
4032 BRepBuilderAPI_Transform myBRepTransformation2(myBRepTransformation1.Shape(), theTransformation2, Standard_False) ;
4033 B.Add( compound, myBRepTransformation2.Shape() );
4037 result = CreateObject(tds) ;
4039 catch(Standard_Failure) {
4040 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMultiRotation2D", SALOME::BAD_PARAM);
4043 if( CORBA::is_nil(result) ) {
4044 THROW_SALOME_CORBA_EXCEPTION("MakeMultiRotation2D aborted : null result", SALOME::BAD_PARAM);
4046 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4051 //=================================================================================
4052 // function : MakeCopy()
4053 // purpose : Copy a 3D shape
4054 //=================================================================================
4055 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCopy( GEOM::GEOM_Shape_ptr Shape)
4056 throw (SALOME::SALOME_Exception)
4058 GEOM::GEOM_Shape_var result ;
4060 TopoDS_Shape aShape = GetTopoShape(Shape) ;
4061 if(aShape.IsNull() ) {
4062 THROW_SALOME_CORBA_EXCEPTION("Copy aborted : null shape during operation", SALOME::BAD_PARAM);
4064 BRepBuilderAPI_Copy Copy(aShape);
4065 if( Copy.IsDone() ) {
4067 result = CreateObject(tds);
4068 InsertInLabelOneArgument(aShape, Shape, tds, result, myCurrentOCAFDoc) ;
4075 //=================================================================================
4076 // function : MakeMirrorByPlane()
4077 // purpose : build a shape by symmetry of 'myShape' with 'shapePlane' in argument
4078 //=================================================================================
4079 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMirrorByPlane(GEOM::GEOM_Shape_ptr myShape,
4080 GEOM::GEOM_Shape_ptr shapePlane)
4081 throw (SALOME::SALOME_Exception)
4083 GEOM::GEOM_Shape_var result ;
4085 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4086 TopoDS_Shape aShapePlane = GetTopoShape(shapePlane) ;
4087 if( aShape.IsNull() || aShapePlane.IsNull() ) {
4088 THROW_SALOME_CORBA_EXCEPTION("Mirror aborted : null shape argument", SALOME::BAD_PARAM);
4092 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(aShapePlane)) ;
4093 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf) ;
4094 const gp_Ax3 pos = myPlane->Position() ;
4095 const gp_Pnt loc = pos.Location() ; /* location of the plane */
4096 const gp_Dir dir = pos.Direction() ; /* Main direction of the plane (Z axis) */
4098 /* plane used for mirroring */
4099 gp_Ax2 pln(loc, dir) ;
4100 gp_Trsf theTransformation ;
4101 theTransformation.SetMirror(pln) ;
4102 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
4104 tds = myBRepTransformation.Shape() ;
4106 THROW_SALOME_CORBA_EXCEPTION("Mirror aborted", SALOME::BAD_PARAM);
4109 catch(Standard_Failure) {
4110 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMirrorByPlane", SALOME::BAD_PARAM);
4113 result = CreateObject(tds) ;
4115 /* Insert arguments in ocaf */
4116 GEOM::GEOM_Gen::ListOfIOR_var ListShapes = new GEOM::GEOM_Gen::ListOfIOR;
4117 ListShapes->length(2);
4118 ListShapes[0] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(myShape)) ;
4119 ListShapes[1] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(shapePlane)) ;
4120 InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
4126 //=================================================================================
4127 // function : MakeRotation()
4128 // purpose : Rotation of a 3D shape around an axis
4129 //=================================================================================
4130 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeRotation( GEOM::GEOM_Shape_ptr myShape,
4131 const GEOM::AxisStruct& axis,
4132 CORBA::Double angle)
4133 throw (SALOME::SALOME_Exception)
4135 GEOM::GEOM_Shape_var result ;
4137 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4138 if( aShape.IsNull() ) {
4139 THROW_SALOME_CORBA_EXCEPTION("Rotation aborted : null shape during operation", SALOME::BAD_PARAM);
4143 gp_Pnt P(axis.x, axis.y, axis.z) ;
4144 gp_Dir D(axis.vx, axis.vy, axis.vz) ;
4147 gp_Trsf theTransformation ;
4148 theTransformation.SetRotation(AX, angle) ;
4149 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
4150 tds = myBRepTransformation.Shape() ;
4152 catch(Standard_Failure) {
4153 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeRotation", SALOME::BAD_PARAM);
4156 if ( !tds.IsNull() ) {
4157 result = CreateObject(tds) ;
4158 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4164 //=================================================================================
4165 // function : MakeScaleTransform()
4166 // purpose : Make a shape multipling another by a scale factor
4167 //=================================================================================
4168 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeScaleTransform(GEOM::GEOM_Shape_ptr myShape,
4169 const GEOM::PointStruct& theCenterOfScale,
4170 CORBA::Double factor)
4171 throw (SALOME::SALOME_Exception)
4173 GEOM::GEOM_Shape_var result ;
4175 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4176 if( aShape.IsNull() ) {
4177 THROW_SALOME_CORBA_EXCEPTION("Scale aborted : null shape during operation", SALOME::BAD_PARAM);
4181 gp_Pnt Pcenter(theCenterOfScale.x, theCenterOfScale.y, theCenterOfScale.z) ;
4182 gp_Trsf theTransformation ;
4183 theTransformation.SetScale(Pcenter, factor) ;
4184 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
4185 tds = myBRepTransformation.Shape() ;
4187 catch(Standard_Failure) {
4188 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeScaleTransform", SALOME::BAD_PARAM);
4191 if ( !tds.IsNull() ) {
4192 result = CreateObject(tds) ;
4193 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4199 //=================================================================================
4200 // function : MakeCompound()
4201 // purpose : Make a compound from a list containing one or more shapes
4202 //=================================================================================
4203 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCompound( const GEOM::GEOM_Gen::ListOfIOR& ListShapes )
4204 throw (SALOME::SALOME_Exception)
4206 GEOM::GEOM_Shape_var result ;
4208 BRep_Builder aBuilder;
4209 aBuilder.MakeCompound(C) ;
4211 for ( unsigned int i = 0; i < ListShapes.length(); i++) {
4212 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[i] );
4213 TopoDS_Shape Shape = GetTopoShape(aShape) ;
4214 if( Shape.IsNull() ) {
4215 THROW_SALOME_CORBA_EXCEPTION("Compound aborted : null shape during operation", SALOME::BAD_PARAM);
4217 aBuilder.Add(C, Shape) ;
4221 THROW_SALOME_CORBA_EXCEPTION("Null result : Compound operation aborted", SALOME::BAD_PARAM);
4224 result = CreateObject(C) ;
4225 InsertInLabelMoreArguments(C, result, ListShapes, myCurrentOCAFDoc) ;
4232 //================================================================================
4233 // function : MakeEdge()
4234 // purpose : Make a linear edge with 2 points
4235 //================================================================================
4236 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeEdge(const GEOM::PointStruct& pstruct1,
4237 const GEOM::PointStruct& pstruct2)
4238 throw (SALOME::SALOME_Exception)
4240 GEOM::GEOM_Shape_var result ;
4244 gp_Pnt P1(pstruct1.x, pstruct1.y, pstruct1.z);
4245 gp_Pnt P2(pstruct2.x, pstruct2.y, pstruct2.z) ;
4246 tds = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
4248 THROW_SALOME_CORBA_EXCEPTION("MakeEdge aborted : null result", SALOME::BAD_PARAM);
4250 catch (Standard_Failure) {
4251 THROW_SALOME_CORBA_EXCEPTION("Exception catched in MakeEdge", SALOME::BAD_PARAM);
4254 result = CreateObject(tds) ;
4255 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
4256 result->ShapeId(entry);
4262 //=================================================================================
4263 // function : MakeWire()
4264 // purpose : Make a wire from a list containing one or more edges or wires that can
4266 //=================================================================================
4267 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeWire( const GEOM::GEOM_Gen::ListOfIOR& ListShapes )
4268 throw (SALOME::SALOME_Exception)
4270 GEOM::GEOM_Shape_var result ;
4271 BRepBuilderAPI_MakeWire MW ;
4272 TopoDS_Shape tds, Shape ;
4275 for ( unsigned int i = 0; i < ListShapes.length(); i++) {
4276 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[i] );
4277 Shape = GetTopoShape(aShape) ;
4278 if( Shape.IsNull() ) {
4279 THROW_SALOME_CORBA_EXCEPTION("MakeWire aborted : null shape during operation", SALOME::BAD_PARAM);
4281 if( Shape.ShapeType() == TopAbs_EDGE )
4282 MW.Add( TopoDS::Edge(Shape) ) ;
4283 if (Shape.ShapeType() == TopAbs_WIRE )
4284 MW.Add( TopoDS::Wire(Shape) ) ;
4289 catch(Standard_Failure) {
4290 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeWire", SALOME::BAD_PARAM);
4293 if( tds.IsNull() ) {
4294 THROW_SALOME_CORBA_EXCEPTION("Make Wire operation aborted : null result", SALOME::BAD_PARAM);
4297 result = CreateObject(tds) ;
4298 InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
4305 //=================================================================================
4306 // function : MakeRevolution()
4308 //=================================================================================
4309 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeRevolution(GEOM::GEOM_Shape_ptr myShape,
4310 const GEOM::AxisStruct& axis,
4312 throw (SALOME::SALOME_Exception)
4314 GEOM::GEOM_Shape_var result ;
4316 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4317 if( aShape.IsNull() ) {
4318 THROW_SALOME_CORBA_EXCEPTION("Revolution aborted : null shape", SALOME::BAD_PARAM);
4321 gp_Pnt P(axis.x, axis.y, axis.z) ;
4322 gp_Dir D(axis.vx, axis.vy, axis.vz);
4324 tds = BRepPrimAPI_MakeRevol(aShape, AX, angle);
4326 catch(Standard_Failure) {
4327 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeRevolution", SALOME::BAD_PARAM);
4330 if( tds.IsNull() ) {
4331 THROW_SALOME_CORBA_EXCEPTION("Revolution aborted", SALOME::BAD_PARAM);
4333 result = CreateObject(tds) ;
4334 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4339 //=================================================================================
4340 // function : MakePipe()
4341 // purpose : Create a shape by sweeping a baseShape along a pathShape
4342 //=================================================================================
4343 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePipe( GEOM::GEOM_Shape_ptr pathShape,
4344 GEOM::GEOM_Shape_ptr baseShape )
4345 throw (SALOME::SALOME_Exception)
4347 GEOM::GEOM_Shape_var result ;
4350 TopoDS_Shape pathTds = GetTopoShape(pathShape) ;
4351 TopoDS_Shape baseTds = GetTopoShape(baseShape) ;
4353 if( baseTds.IsNull() || pathTds.IsNull() ) {
4354 THROW_SALOME_CORBA_EXCEPTION("MakePipe aborted : null shape argument", SALOME::BAD_PARAM);
4357 if( pathTds.ShapeType() == TopAbs_WIRE ) {
4358 aWire = TopoDS::Wire(pathTds) ;
4361 if ( pathTds.ShapeType() == TopAbs_EDGE ) {
4362 TopoDS_Edge aEdge = TopoDS::Edge(pathTds) ;
4363 aWire = BRepBuilderAPI_MakeWire(aEdge);
4366 THROW_SALOME_CORBA_EXCEPTION("MakePipe aborted : bad shape type", SALOME::BAD_PARAM);
4371 tds = BRepOffsetAPI_MakePipe(aWire, baseTds) ;
4373 catch(Standard_Failure) {
4374 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePipe", SALOME::BAD_PARAM);
4377 if ( !IsValid(tds) ) {
4378 THROW_SALOME_CORBA_EXCEPTION("MakePipe aborted : non valid shape result", SALOME::BAD_PARAM);
4381 result = CreateObject(tds) ;
4383 /* Insert arguments in ocaf */
4384 GEOM::GEOM_Gen::ListOfIOR_var ListShapes = new GEOM::GEOM_Gen::ListOfIOR;
4385 ListShapes->length(2);
4386 ListShapes[0] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(pathShape)) ;
4387 ListShapes[1] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(baseShape)) ;
4388 InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
4394 //=================================================================================
4395 // function : MakePrism()
4396 // purpose : uses myShape as base and the vector P1 to P2
4397 //=================================================================================
4398 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePrism( GEOM::GEOM_Shape_ptr myShape,
4399 const GEOM::PointStruct& P1,
4400 const GEOM::PointStruct& P2 )
4401 throw (SALOME::SALOME_Exception)
4403 GEOM::GEOM_Shape_var result ;
4405 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4406 if( aShape.IsNull() ) {
4407 THROW_SALOME_CORBA_EXCEPTION("Prism aborted : null shape operation", SALOME::BAD_PARAM);
4411 gp_Vec Vector (P2.x - P1.x, P2.y - P1.y, P2.z - P1.z) ;
4412 tds = BRepPrimAPI_MakePrism(aShape, Vector, Standard_False).Shape() ;
4414 catch(Standard_Failure) {
4415 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePipe", SALOME::BAD_PARAM);
4418 if ( tds.IsNull() ) {
4419 THROW_SALOME_CORBA_EXCEPTION("Prism aborted", SALOME::BAD_PARAM);
4422 result = CreateObject(tds) ;
4423 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4429 //=================================================================================
4430 // function : MakeCDG()
4431 // purpose : Create a CDG topology.
4432 //=================================================================================
4433 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCDG(GEOM::GEOM_Shape_ptr aShape)
4434 throw (SALOME::SALOME_Exception)
4436 GEOM::GEOM_Shape_var result ;
4438 TopoDS_Shape shape = GetTopoShape(aShape) ;
4439 GProp_GProps System;
4440 gp_Pnt myCenterMass ;
4442 if( shape.IsNull() ) {
4443 THROW_SALOME_CORBA_EXCEPTION("MakeCDG aborted : null shape argument", SALOME::BAD_PARAM);
4447 if ( shape.ShapeType() == TopAbs_VERTEX) {
4448 myCenterMass = BRep_Tool::Pnt(TopoDS::Vertex( shape ));
4450 else if ( shape.ShapeType() == TopAbs_EDGE || shape.ShapeType() == TopAbs_WIRE ) {
4451 BRepGProp::LinearProperties(shape, System);
4452 myCenterMass = System.CentreOfMass() ;
4454 else if ( shape.ShapeType() == TopAbs_FACE || shape.ShapeType() == TopAbs_SHELL ) {
4455 BRepGProp::SurfaceProperties(shape, System);
4456 myCenterMass = System.CentreOfMass() ;
4459 BRepGProp::VolumeProperties(shape, System);
4460 myCenterMass = System.CentreOfMass() ;
4463 tds = BRepBuilderAPI_MakeVertex(myCenterMass).Shape() ;
4465 catch(Standard_Failure) {
4466 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeCDG", SALOME::BAD_PARAM);
4469 if ( tds.IsNull() ) {
4470 THROW_SALOME_CORBA_EXCEPTION("Make CDG aborted : null shape result", SALOME::BAD_PARAM);
4473 result = CreateObject(tds) ;
4474 InsertInLabelOneArgument(shape, aShape, tds, result, myCurrentOCAFDoc) ;
4480 //=================================================================================
4481 // function : Archimede()
4483 //=================================================================================
4484 GEOM::GEOM_Shape_ptr GEOM_Gen_i::Archimede(GEOM::GEOM_Shape_ptr aShape,
4485 CORBA::Double aWeight,
4486 CORBA::Double aWaterDensity,
4487 CORBA::Double aMeshingDeflection)
4488 throw (SALOME::SALOME_Exception)
4490 GEOM::GEOM_Shape_var result;
4493 if (aWaterDensity != 0.)
4494 cste = aWeight/aWaterDensity;
4496 THROW_SALOME_CORBA_EXCEPTION("Water density is null", SALOME::BAD_PARAM);
4498 TopoDS_Shape shape = GetTopoShape(aShape) ;
4499 if( shape.IsNull() ) {
4500 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
4503 gp_Dir direct(0.0,0.0,1.0);
4504 gp_Pnt PosPlan(0.0,0.0,0.0);
4505 Geom_Plane PP (PosPlan,direct);
4506 Handle(Geom_Geometry) G = PP.Copy();
4507 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(G);
4509 gp_Dir Zdirection(0.0,0.0,1.0);
4510 VolumeSection VOL( shape, aMeshingDeflection);
4512 Handle (Geom_RectangularTrimmedSurface) SurfaceTrimmee;
4514 if(Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
4515 VOL.MakeRotation(direct);
4518 VOL.CenterOfGravity();
4519 SurfaceTrimmee = VOL.TrimSurf();
4520 Standard_Real Cote = VOL.Archimede( cste, aMeshingDeflection );
4524 VOL.getZ(Zmin,Zmax);
4525 double volume = VOL.CalculateVolume( Zmax ) * aWaterDensity;
4528 sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
4530 THROW_SALOME_CORBA_EXCEPTION(msg, SALOME::BAD_PARAM);
4533 SurfaceTrimmee=VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
4534 if(Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
4535 SurfaceTrimmee=VOL.InvMakeRotation(direct,SurfaceTrimmee);
4538 Standard_Real u1,u2,v1,v2;
4539 SurfaceTrimmee->Bounds(u1,u2,v1,v2);
4540 TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2);
4542 if (tirant.IsNull()) {
4543 THROW_SALOME_CORBA_EXCEPTION("Result is null", SALOME::BAD_PARAM);
4546 result = CreateObject(tirant);
4547 InsertInLabelOneArgument(shape, aShape, tirant, result, myCurrentOCAFDoc) ;
4553 //================================================================================
4554 // function : MakeFillet()
4555 // purpose : Create a cylinder topology
4556 //================================================================================
4557 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFillet( GEOM::GEOM_Shape_ptr shape,
4558 CORBA::Double radius,
4559 CORBA::Short ShapeType,
4560 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID )
4561 throw (SALOME::SALOME_Exception)
4563 GEOM::GEOM_Shape_var result;
4566 const TopoDS_Shape aShape = GetTopoShape(shape) ;
4567 if( aShape.IsNull() ) {
4568 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
4571 BRepFilletAPI_MakeFillet fill(aShape);
4575 if(ListOfID.length() == 0) {
4576 TopExp_Explorer Exp ( aShape, TopAbs_EDGE );
4577 for (Exp; Exp.More(); Exp.Next()) {
4578 TopoDS_Edge E =TopoDS::Edge(Exp.Current());
4581 for (int i = 1;i<=fill.NbContours();i++) {
4582 fill.SetRadius(radius,i);
4588 /* case selection */
4589 for ( unsigned int ind = 0; ind < ListOfID.length(); ind++ ) {
4591 if( GetShapeFromIndex( aShape, (TopAbs_ShapeEnum)ShapeType, ListOfID[ind], ss ) ) {
4592 TopoDS_Edge E = TopoDS::Edge(ss) ;
4596 for (int i = 1;i<=fill.NbContours();i++) {
4597 fill.SetRadius(radius,i);
4602 catch(Standard_Failure) {
4603 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeFillet", SALOME::BAD_PARAM);
4607 THROW_SALOME_CORBA_EXCEPTION("Make Fillet aborted", SALOME::BAD_PARAM);
4609 result = CreateObject(tds);
4610 InsertInLabelOneArgument(aShape, shape, tds, result, myCurrentOCAFDoc) ;
4616 //================================================================================
4617 // function : MakeChamfer
4618 // purpose : Create a Chamfer topology
4619 //================================================================================
4620 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeChamfer( GEOM::GEOM_Shape_ptr shape,
4623 CORBA::Short ShapeType,
4624 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID )
4625 throw (SALOME::SALOME_Exception)
4627 GEOM::GEOM_Shape_var result;
4630 const TopoDS_Shape aShape = GetTopoShape(shape) ;
4631 if( aShape.IsNull() ) {
4632 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
4635 BRepFilletAPI_MakeChamfer MC(aShape);
4639 TopTools_IndexedDataMapOfShapeListOfShape M;
4640 TopExp::MapShapesAndAncestors(aShape,TopAbs_EDGE,TopAbs_FACE,M);
4641 if(ListOfID.length() == 0) {
4642 for (int i = 1;i<=M.Extent();i++) {
4643 TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
4644 TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
4645 if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
4652 /* case selection */
4653 for ( unsigned int ind = 0; ind < ListOfID.length(); ind++ ) {
4655 if( GetShapeFromIndex( aShape, (TopAbs_ShapeEnum)ShapeType, ListOfID[ind], ss ) ) {
4656 TopoDS_Edge E = TopoDS::Edge( ss ) ;
4657 TopoDS_Face F = TopoDS::Face(M.FindFromKey(E).First());
4658 if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
4665 catch(Standard_Failure) {
4666 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeChamfer", SALOME::BAD_PARAM);
4670 THROW_SALOME_CORBA_EXCEPTION("Make Chamfer aborted", SALOME::BAD_PARAM);
4672 result = CreateObject(tds);
4673 InsertInLabelOneArgument(aShape, shape, tds, result, myCurrentOCAFDoc) ;
4678 //=================================================================================
4679 // function : CheckShape()
4681 //=================================================================================
4682 CORBA::Boolean GEOM_Gen_i::CheckShape(GEOM::GEOM_Shape_ptr shape)
4683 throw (SALOME::SALOME_Exception)
4685 TopoDS_Shape S = GetTopoShape(shape) ;
4687 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
4690 BRepCheck_Analyzer ana(S,false);
4697 //=================================================================================
4698 // function : MakePlacedBox()
4700 //=================================================================================
4701 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePlacedBox(CORBA::Double x1, CORBA::Double y1, CORBA::Double z1,
4702 CORBA::Double delta1, CORBA::Double delta2, CORBA::Double delta3)
4703 throw (SALOME::SALOME_Exception)
4705 GEOM::GEOM_Shape_var result ;
4708 CORBA::Double x2, y2, z2 ;
4715 gp_Pnt P1(x1,y1,z1);
4716 gp_Pnt P2(x2,y2,z2);
4718 tds = BRepPrimAPI_MakeBox(P1,P2).Shape();
4720 catch(Standard_Failure) {
4721 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeBox", SALOME::BAD_PARAM);
4725 THROW_SALOME_CORBA_EXCEPTION("Make Box aborted : null shape", SALOME::BAD_PARAM);
4728 result = CreateObject(tds);
4729 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
4730 result->ShapeId(entry) ;
4735 //=================================================================================
4736 // function : MakePanel()
4738 //=================================================================================
4739 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePanel(GEOM::GEOM_Shape_ptr shape,
4740 CORBA::Short directiontype,
4741 CORBA::Double delta)
4742 throw (SALOME::SALOME_Exception)
4744 GEOM::GEOM_Shape_var result ;
4746 TopoDS_Shape aShape = GetTopoShape(shape) ;
4748 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax ;
4749 GEOM::PointStruct pstruct1, pstruct2, pstruct3, pstruct4 ;
4751 if(aShape.IsNull() ) {
4752 THROW_SALOME_CORBA_EXCEPTION("MakePanel aborted : null shape during operation", SALOME::BAD_PARAM);
4756 BRepBndLib::Add(aShape,B);
4758 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
4760 switch (directiontype)
4763 pstruct1 = MakePointStruct( delta, aymin, azmin ) ;
4764 pstruct2 = MakePointStruct( delta, aymin, azmax ) ;
4765 pstruct3 = MakePointStruct( delta, aymax, azmax ) ;
4766 pstruct4 = MakePointStruct( delta, aymax, azmin ) ;
4769 pstruct1 = MakePointStruct( axmin, delta, azmin ) ;
4770 pstruct2 = MakePointStruct( axmin, delta, azmax ) ;
4771 pstruct3 = MakePointStruct( axmax, delta, azmax ) ;
4772 pstruct4 = MakePointStruct( axmax, delta, azmin ) ;
4775 pstruct1 = MakePointStruct( axmin, aymin, delta ) ;
4776 pstruct2 = MakePointStruct( axmin, aymax, delta ) ;
4777 pstruct3 = MakePointStruct( axmax, aymax, delta ) ;
4778 pstruct4 = MakePointStruct( axmax, aymin, delta ) ;
4784 GEOM::GEOM_Shape_ptr Edge1 = MakeEdge(pstruct1, pstruct2);
4785 GEOM::GEOM_Shape_ptr Edge2 = MakeEdge(pstruct2, pstruct3);
4786 GEOM::GEOM_Shape_ptr Edge3 = MakeEdge(pstruct3, pstruct4);
4787 GEOM::GEOM_Shape_ptr Edge4 = MakeEdge(pstruct4, pstruct1);
4789 GEOM::GEOM_Gen::ListOfIOR_var aList = new GEOM::GEOM_Gen::ListOfIOR;
4791 aList[0]=strdup(Edge1->Name());
4792 aList[1]=strdup(Edge2->Name());
4793 aList[2]=strdup(Edge3->Name());
4794 aList[3]=strdup(Edge4->Name());
4796 GEOM::GEOM_Shape_ptr aWire = MakeWire( aList );
4797 GEOM::GEOM_Shape_ptr aFace = MakeFace( aWire, true ) ;
4798 tds = GetTopoShape(aFace);
4801 catch(Standard_Failure) {
4802 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePanel", SALOME::BAD_PARAM);
4806 THROW_SALOME_CORBA_EXCEPTION("Make PanelsPartition aborted : null shape", SALOME::BAD_PARAM);
4809 result = CreateObject(tds);
4810 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
4811 result->ShapeId(entry) ;
4817 void GEOM_Gen_i::ExportIGES(const char* filename,GEOM::GEOM_Shape_ptr theShape)
4818 throw (SALOME::SALOME_Exception)
4820 if (theShape->_is_nil())
4822 THROW_SALOME_CORBA_EXCEPTION("Export IGES aborted", SALOME::BAD_PARAM);
4824 TopoDS_Shape tds = GetTopoShape(theShape);
4827 THROW_SALOME_CORBA_EXCEPTION("Export IGES aborted", SALOME::BAD_PARAM);
4831 //VRV: OCC 4.0 migration
4832 IGESControl_Controller::Init();
4833 IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"),
4834 Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
4835 //VRV: OCC 4.0 migration
4839 char * aname = strdup(filename);
4840 Standard_Boolean result = ICW.Write( aname );
4843 catch(Standard_Failure)
4845 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ExportIGES", SALOME::BAD_PARAM);
4849 void GEOM_Gen_i::ExportBREP(const char* filename,GEOM::GEOM_Shape_ptr theShape)
4850 throw (SALOME::SALOME_Exception)
4852 if (theShape->_is_nil())
4854 THROW_SALOME_CORBA_EXCEPTION("Export BRep aborted", SALOME::BAD_PARAM);
4856 TopoDS_Shape tds = GetTopoShape(theShape);
4859 THROW_SALOME_CORBA_EXCEPTION("Export BRep aborted", SALOME::BAD_PARAM);
4863 char * aname = strdup(filename);
4864 Standard_Boolean result = BRepTools::Write(tds,aname);
4867 catch(Standard_Failure)
4869 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ExportBREP", SALOME::BAD_PARAM);
4873 void GEOM_Gen_i::ExportSTEP(const char* filename,GEOM::GEOM_Shape_ptr theShape)
4874 throw (SALOME::SALOME_Exception)
4876 if (theShape->_is_nil())
4878 THROW_SALOME_CORBA_EXCEPTION("Export STEP aborted", SALOME::BAD_PARAM);
4880 TopoDS_Shape tds = GetTopoShape(theShape);
4883 THROW_SALOME_CORBA_EXCEPTION("Export STEP aborted", SALOME::BAD_PARAM);
4887 IFSelect_ReturnStatus status ;
4888 //VRV: OCC 4.0 migration
4889 STEPControl_Writer aWriter;
4890 status = aWriter.Transfer( tds, STEPControl_ManifoldSolidBrep ) ;
4891 //VRV: OCC 4.0 migration
4892 if ( status == IFSelect_RetDone )
4894 char * aname = strdup(filename);
4895 status = aWriter.Write( aname ) ;
4899 catch(Standard_Failure)
4901 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ExportBREP", SALOME::BAD_PARAM);
4906 //=====================================================================================
4908 //=====================================================================================
4911 PortableServer::ObjectId * GeometryEngine_factory(CORBA::ORB_ptr orb,
4912 PortableServer::POA_ptr poa,
4913 PortableServer::ObjectId * contId,
4914 const char *instanceName,
4915 const char * interfaceName)
4918 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
4920 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
4922 return myGEOM_Gen_i->getId() ;