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 #include <BRepAlgoAPI.hxx>
58 #include <BRepAdaptor_Surface.hxx>
59 #include <BRepBuilderAPI_Copy.hxx>
60 #include <BRepAlgoAPI_Common.hxx>
61 #include <BRepAlgoAPI_Cut.hxx>
62 #include <BRepAlgoAPI_Fuse.hxx>
63 #include <BRepAlgoAPI_Section.hxx>
64 #include <BRepOffsetAPI_Sewing.hxx>
65 #include <BRepOffsetAPI_MakePipe.hxx>
67 #include <BRepBuilderAPI_MakeVertex.hxx>
68 #include <BRepBuilderAPI_MakeEdge.hxx>
69 #include <BRepBuilderAPI_MakeFace.hxx>
71 #include <BRepLib.hxx>
72 #include <BRepBndLib.hxx>
73 #include <Bnd_Box.hxx>
75 #include <BRepBuilderAPI_MakeShell.hxx>
76 #include <BRepPrim_Builder.hxx>
77 #include <BRepBuilderAPI_MakeSolid.hxx>
78 #include <BRepClass3d_SolidClassifier.hxx>
80 #include <BRepBuilderAPI_MakeWire.hxx>
81 #include <BRepBuilderAPI_Transform.hxx>
82 #include <BRepPrimAPI_MakeRevol.hxx>
83 #include <BRepPrimAPI_MakePrism.hxx>
84 #include <BRepPrimAPI_MakeTorus.hxx>
85 #include <BRepPrimAPI_MakeBox.hxx>
86 #include <BRepPrimAPI_MakeSphere.hxx>
87 #include <BRepPrimAPI_MakeCylinder.hxx>
88 #include <BRepPrimAPI_MakeCone.hxx>
89 #include <BRepFilletAPI_MakeFillet.hxx>
90 #include <BRepFilletAPI_MakeChamfer.hxx>
91 #include <BRepTools.hxx>
92 #include <BRepTools_Quilt.hxx>
93 #include <BRep_Tool.hxx>
95 #include <GeomAPI_ProjectPointOnCurve.hxx>
97 #include <BRepGProp.hxx>
98 #include <GProp_GProps.hxx>
99 #include <Precision.hxx>
101 //VRV: OCC 4.0 migration
102 #include <STEPControl_Reader.hxx>
103 #include <IGESControl_Reader.hxx>
104 //VRV: OCC 4.0 migration
106 #include <IFSelect_ReturnStatus.hxx>
107 #include <TColStd_HSequenceOfTransient.hxx>
109 //VRV: OCC 4.0 migration
110 #include <IGESControl_Writer.hxx>
111 #include <IGESControl_Controller.hxx>
112 #include <STEPControl_Writer.hxx>
113 #include <Interface_Static.hxx>
114 //#include <STEPControlStd_StepModelType.hxx>
115 //VRV: OCC 4.0 migration
117 #include <TopoDS_Shape.hxx>
118 #include <TopAbs.hxx>
119 #include <TopoDS_Wire.hxx>
120 #include <TopoDS_Edge.hxx>
121 #include <TopoDS_Compound.hxx>
122 #include <TopoDS_Solid.hxx>
124 #include <TopExp.hxx>
125 #include <TopExp_Explorer.hxx>
126 #include <TCollection_ExtendedString.hxx>
127 #include <TopoDS_Iterator.hxx>
128 #include <TopTools_MapOfShape.hxx>
129 #include <TopTools_MapIteratorOfMapOfShape.hxx>
130 #include <TopTools_ListIteratorOfListOfShape.hxx>
131 #include <TopTools_Array1OfShape.hxx>
133 #include <IGESData_IGESEntity.hxx>
135 #include <TDF_Tool.hxx>
136 #include <TDF_Label.hxx>
137 #include <TDataStd_Name.hxx>
138 #include <TDataStd_Comment.hxx>
139 #include <TDF_Reference.hxx>
140 #include <TDF_Data.hxx>
141 #include <TNaming_Builder.hxx>
142 #include <TNaming_NamedShape.hxx>
143 #include <TNaming_Tool.hxx>
144 // #include <TDocStd_Owner.hxx>
146 #include "SALOMEDS_Tool.hxx"
147 #include "GEOMDS_Commands.hxx"
148 #include "GEOMDS_Explorer.hxx"
150 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
152 //============================================================================
153 // function : GEOM_Gen_i()
154 // purpose : constructor to be called for servant creation.
155 //============================================================================
156 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
157 PortableServer::POA_ptr poa,
158 PortableServer::ObjectId * contId,
159 const char *instanceName,
160 const char *interfaceName) :
161 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
164 _id = _poa->activate_object(_thisObj);
166 name_service = new SALOME_NamingService(_orb);
167 myOCAFApp = new GEOMDS_Application();
169 GetCurrentStudy(0);//for correct work of SuperVisor
174 //============================================================================
175 // function : ~GEOM_Gen_i()
176 // purpose : destructor
177 //============================================================================
178 GEOM_Gen_i::~GEOM_Gen_i() {
183 //============================================================================
184 // function : IORToLocalPersistentID()
186 //============================================================================
187 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
188 const char* IORString,
189 CORBA::Boolean isMultiFile,
190 CORBA::Boolean isASCII)
192 GEOM::GEOM_Shape_var aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(IORString));
193 if (!CORBA::is_nil(aShape)) {
194 return strdup(aShape->ShapeId());
200 //============================================================================
201 // function : LocalPersistentIDToIOR()
202 // purpose : Create/Load CORBA object from a persistent ref (an entry)
203 // : Used when a study is loaded
204 // : The IOR (IORName) of object created is returned
205 //============================================================================
206 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
207 const char* aLocalPersistentID,
208 CORBA::Boolean isMultiFile,
209 CORBA::Boolean isASCII)
211 SALOMEDS::Study_var myStudy = theSObject->GetStudy();
212 GetCurrentStudy(myStudy->StudyId());
213 Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(myStudyIDToDoc(myStudy->StudyId()));
214 CORBA::String_var aPersRefString = aLocalPersistentID;
216 /* For a GEOM::GEOM_Shape the pers_ref is the Entry in the OCAF document */
217 TCollection_ExtendedString MainIOR;
219 TDF_Tool::Label(aDoc->GetData(), aPersRefString, Lab );
221 Handle(TNaming_NamedShape) NS;
222 Lab.FindAttribute( TNaming_NamedShape::GetID(), NS );
223 TopoDS_Shape S = TNaming_Tool::GetShape(NS);
225 /* shapetype, index=0, topo, orb, shapetype, ismain=true and name are setted and modified later ? */
226 GEOM::GEOM_Shape_var result = CreateObject(S);
227 GEOMDS_Commands GC( aDoc->Main() ) ;
229 if ( GC.HasIOR(Lab) ) { /* shape already created/loaded */
233 /******************* Dependent object (not a main shape) *********************/
234 if( GC.IsDependentShape(Lab) ) {
236 TDF_Label mainLabel ;
237 Standard_Boolean mainShapeOk = GC.GetMainShapeLabel(Lab, mainLabel) ;
239 /* Main object not yet loaded we load/create it */
240 if( !GC.HasIOR(mainLabel) ) {
242 TCollection_AsciiString entry;
243 TDF_Tool::Entry(mainLabel,entry);
244 CORBA::String_var ent = strdup(entry.ToCString());
246 /* Create the main object recursively */
247 MainIOR = LocalPersistentIDToIOR(theSObject, ent, isMultiFile, isASCII) ;
249 GC.ReturnNameIOR( mainLabel, MainIOR );
252 result->MainName( TCollection_AsciiString(MainIOR).ToCString() ) ;
253 result->IsMainShape(false) ;
254 result->ShapeId(aPersRefString);
256 Handle(TDF_Reference) aRef;
257 Lab.FindAttribute( TDF_Reference::GetID(), aRef );
258 TDF_Label myL = aRef->Get() ;
259 Handle(TNaming_NamedShape) NN;
260 myL.FindAttribute( TNaming_NamedShape::GetID(), NN );
261 TopoDS_Shape mainTopo = TNaming_Tool::GetShape(NN);
263 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
265 if(S.ShapeType() != TopAbs_COMPOUND) {
266 /* to set the index of a unique sub shape (Explode All ONLY for the moment !) */
269 TopTools_MapOfShape M;
270 TopExp_Explorer Exp ;
271 for( Exp.Init(mainTopo, TopAbs_ShapeEnum( result->ShapeType() )) ; Exp.More(); Exp.Next() ) {
272 if ( M.Add(Exp.Current()) ) {
273 if(Exp.Current().IsSame(S) ) {
280 result->Index(ListOfID) ;
281 return result->Name();
284 /* Here is a TopAbs_COMPOUND : we set the list/index for a compound : containing two or more sub shapes */
285 /* Warning : the Corba shape has a shapetype Compound : in GEOMDS_Client we have to retrieve the kind of */
286 /* subshapes contained in this compound ! */
287 TopTools_SequenceOfShape SS;
289 TopExp_Explorer exp ;
290 TopAbs_ShapeEnum subType ;
292 /* Set all sub shapes in a sequence of shapes */
293 for ( it.Initialize( S, true, true ) ; it.More(); it.Next() ) {
294 subType = it.Value().ShapeType() ;
295 SS.Append( it.Value() ) ;
298 ListOfID->length( SS.Length() ) ;
299 int j, k ; /* in TopTools_SequenceOfShape index start at 1 */
301 for( k=1; k<=SS.Length(); k++ ) {
303 for( exp.Init( mainTopo, subType ); exp.More(); exp.Next() ) {
304 if( exp.Current().IsSame( SS.Value(k) ) ) {
310 result->Index(ListOfID) ;
311 return result->Name();
315 /******************* Independent object (not a sub shape) *********************/
317 result->IsMainShape(true) ;
318 if( !GC.AddIORNameAttribute(Lab, result->Name() ) ) {
319 MESSAGE("in LocalPersistentIDToIOR, NAME/IOR attribute already exist." << endl ) ;
321 Handle(TNaming_NamedShape) NamedShape ;
322 bool notTested = Lab.FindAttribute(TNaming_NamedShape::GetID(), NamedShape) ;
323 result->ShapeId(aPersRefString);
324 return result->Name();
328 //============================================================================
329 // function : CanPublishInStudy
331 //============================================================================
332 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
334 GEOM::GEOM_Shape_var aShape = GEOM::GEOM_Shape::_narrow(theIOR);
335 return !(aShape->_is_nil());
339 //============================================================================
340 // function : PublishInStudy
342 //============================================================================
343 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
344 SALOMEDS::SObject_ptr theSObject,
345 CORBA::Object_ptr theObject,
346 const char* theName) throw (SALOME::SALOME_Exception)
348 SALOMEDS::SObject_var aResultSO;
349 if(CORBA::is_nil(theObject)) return aResultSO;
351 GEOM::GEOM_Shape_var aShape = GEOM::GEOM_Shape::_narrow(theObject);
352 if(aShape->_is_nil()) return aResultSO;
354 if(theStudy->_is_nil()) return aResultSO;
356 SALOMEDS::GenericAttribute_var anAttr;
357 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
359 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
360 if (aFather->_is_nil()) {
361 aFather = aStudyBuilder->NewComponent("GEOM");
362 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
363 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
364 aName->SetValue("Geometry");
365 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
366 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
367 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
369 if (aFather->_is_nil()) return aResultSO;
371 if (CORBA::is_nil(theSObject)) {
372 aResultSO = aStudyBuilder->NewObject(aFather);
374 if (!theSObject->ReferencedObject(aResultSO))
375 THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
377 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
378 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
379 anIOR->SetValue(aShape->Name());
381 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
382 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
383 TCollection_AsciiString aShapeName("Shape_");
385 if ( aShape->ShapeType() == GEOM::COMPOUND ) {
386 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
387 aShapeName = "Compound_";
388 } else if ( aShape->ShapeType() == GEOM::COMPSOLID ) {
389 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
390 aShapeName = "Compsolid_";
391 } else if ( aShape->ShapeType() == GEOM::SOLID ) {
392 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
393 aShapeName = "Solid_";
394 } else if ( aShape->ShapeType() == GEOM::SHELL ) {
395 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
396 aShapeName = "Shell_";
397 } else if ( aShape->ShapeType() == GEOM::FACE ) {
398 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
399 aShapeName = "Face_";
400 } else if ( aShape->ShapeType() == GEOM::WIRE ) {
401 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
402 aShapeName = "Wire_";
403 } else if ( aShape->ShapeType() == GEOM::EDGE ) {
404 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
405 aShapeName = "Edge_";
406 } else if ( aShape->ShapeType() == GEOM::VERTEX ) {
407 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
408 aShapeName = "Vertex_";
410 if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
411 else aShapeName = TCollection_AsciiString(strdup(theName));
413 //Set a name of the added shape
414 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
415 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
416 aNameAttrib->SetValue(aShapeName.ToCString());
418 //Add a reference to published object
419 // aStudyBuilder->Addreference(theObject, aResultSO);
420 return aResultSO._retn();
424 //============================================================================
426 // purpose : save OCAF/Geom document
427 //============================================================================
428 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
431 SALOMEDS::TMPFile_var aStreamFile;
432 // Get a temporary directory to store a file
433 TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
434 // Create a list to store names of created files
435 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
437 // Prepare a file name to open
438 TCollection_AsciiString aNameWithExt(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
439 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
440 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
441 // Build a full file name of temporary file
442 TCollection_AsciiString aFullName = aTmpDir + aNameWithExt;
443 // Save GEOM component in this file
444 myOCAFApp->SaveAs(myCurrentOCAFDoc, aFullName);
445 // Conver a file to the byte stream
446 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
447 // Remove the created file and tmp directory
448 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
449 // Return the created byte stream
450 return aStreamFile._retn();
453 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
456 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
457 return aStreamFile._retn();
461 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
462 const SALOMEDS::TMPFile& theStream,
466 if (theStream.length() <= 9) {
467 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
471 // Get a temporary directory for a file
472 TCollection_AsciiString aTmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
473 // Conver the byte stream theStream to a file and place it in tmp directory
474 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
478 // Prepare a file name to open
479 TCollection_AsciiString aNameWithExt(aSeq[0]);
480 TCollection_AsciiString aFullName = aTmpDir + aNameWithExt;
483 if (myOCAFApp->Open(aFullName, myCurrentOCAFDoc) != CDF_RS_OK) return false;
485 // Remove the created file and tmp directory
486 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
488 SALOMEDS::Study_var Study = theComponent->GetStudy();
489 TCollection_AsciiString name( strdup(Study->Name()) );
491 int StudyID = Study->StudyId();
492 myStudyIDToDoc.Bind( StudyID, myCurrentOCAFDoc );
495 /* We clear all IOR (nameIOR) attributes of all objects before reconstruction */
496 /* This information will be setted when each object is reconstructed */
497 GEOMDS_Commands GC( myCurrentOCAFDoc->Main() ) ;
498 GC.ClearAllIOR(myCurrentOCAFDoc->Main());
503 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
504 const SALOMEDS::TMPFile& theStream,
507 return Load(theComponent, theStream, theURL, isMultiFile);
510 // //============================================================================
511 // // function : Save()
512 // // purpose : save OCAF/Geom document
513 // //============================================================================
514 // void GEOM_Gen_i::Save(const char *IORSComponent, const char *aUrlOfFile)
517 // TCollection_ExtendedString path(strdup(aUrlOfFile));
518 // TCollection_ExtendedString pathWithExt = path + TCollection_ExtendedString(".sgd");
519 // myOCAFApp->SaveAs(myCurrentOCAFDoc,pathWithExt);
523 // //============================================================================
524 // // function : Load()
525 // // purpose : Load OCAF/Geom document
526 // //============================================================================
527 // void GEOM_Gen_i::Load(const char *IORSComponent, const char *aUrlOfFile)
530 // TCollection_ExtendedString path(strdup(aUrlOfFile));
531 // TCollection_ExtendedString pathWithExt = path + TCollection_ExtendedString(".sgd");
533 // myOCAFApp->Open(pathWithExt,myCurrentOCAFDoc);
535 // SALOMEDS::SComponent_var SC = SALOMEDS::SComponent::_narrow(_orb->string_to_object(IORSComponent));
536 // SALOMEDS::Study_var Study = SC->GetStudy();
537 // TCollection_AsciiString name( strdup(Study->Name()) );
539 // int StudyID = Study->StudyId();
540 // myStudyIDToDoc.Bind( StudyID, myCurrentOCAFDoc );
541 // myStudyID = StudyID;
543 // /* We clear all IOR (nameIOR) attributes of all objects before reconstruction */
544 // /* This information will be setted when each object is reconstructed */
545 // GEOMDS_Commands GC( myCurrentOCAFDoc->Main() ) ;
546 // GC.ClearAllIOR(myCurrentOCAFDoc->Main());
552 //============================================================================
553 // function : Close()
555 //============================================================================
556 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
558 int anID = theComponent->GetStudy()->StudyId();
559 if (anID == myStudyID) GetCurrentStudy(0); // set default value of current study ID, if current is deleted
560 if (myStudyIDToDoc.IsBound(anID)) {
561 // close document in the application
562 // Handle(TDocStd_Owner) anOwner;
563 Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(myStudyIDToDoc.Find(anID));
564 // Handle(TDocStd_Document) anEmptyDoc;
565 // if (aDoc->Main().Root().FindAttribute(TDocStd_Owner::GetID(), anOwner)) {
566 // anOwner->SetDocument(anEmptyDoc);
567 // cout<<"********** Nullify owner of document"<<endl;
569 myOCAFApp->Close(aDoc);
570 myStudyIDToDoc.UnBind(anID); // remove document from GEOM documents data map
574 //============================================================================
575 // function : CanCopy()
577 //============================================================================
578 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
579 // Try to retrieve known by Geometry component GEOM_shape by given IOR
580 SALOMEDS::GenericAttribute_var anAttr;
581 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
582 GEOM::GEOM_Shape_var aShape = GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
583 // If the object is null one it can't be copied: return false
584 if (aShape->_is_nil()) return false;
588 //============================================================================
589 // function : CopyFrom()
591 //============================================================================
592 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
593 // Declare a sequence of the byte to store the copied object
594 SALOMEDS::TMPFile_var aStreamFile;
596 // Try to get GEOM_Shape object by given SObject
597 SALOMEDS::GenericAttribute_var anAttr;
598 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
599 GEOM::GEOM_Shape_var aShape = GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
600 // If the object is null one it can't be copied: return false
601 if (aShape->_is_nil()) return aStreamFile._retn();
603 GetCurrentStudy(theObject->GetStudy()->StudyId());
605 // Convert a TopoDS_Shape to a stream of bytes
606 TopoDS_Shape aTopology = GetTopoShape(aShape);
607 if (aTopology.IsNull()) return aStreamFile._retn();
608 ostrstream aStreamedShape;
609 BRepTools::Write(aTopology, aStreamedShape);
610 int aSize = aStreamedShape.pcount();
611 char* aBuffer = new char[aSize];
612 memcpy(aBuffer, aStreamedShape.str(), aSize);
613 aStreamedShape.rdbuf()->freeze(0);
615 aStreamFile = new SALOMEDS::TMPFile(aSize, aSize, (CORBA::Octet*)aBuffer, 1);
617 // Assign an ID = 1 the the type GEOM_Shape
620 // Return created TMPFile
621 return aStreamFile._retn();
624 //============================================================================
625 // function : CanPaste()
627 //============================================================================
628 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
629 // The Geometry component can paste only objects copied by Geometry component
630 // and with the object type = 1
631 // cout<<"********** GEOM_Gen_i::CanPaste ("<<theComponentName<<","<<theObjectID<<")"<<endl;
632 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
636 //============================================================================
637 // function : PasteInto()
639 //============================================================================
640 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
641 CORBA::Long theObjectID,
642 SALOMEDS::SObject_ptr theObject) {
643 // Find the current Study and StudyBuilder
644 SALOMEDS::Study_var aStudy = theObject->GetStudy();
645 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
647 // Retrieve a TopoDS_Shape from byte stream
648 TopoDS_Shape aTopology;
649 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
650 BRep_Builder aBuilder;
652 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
653 } catch (Standard_Failure) {
654 // cout<<"GEOM_Gen_i::PasteInto exception"<<endl;
658 // Create new object in Geometry component using retrieved topology
659 GEOM::GEOM_Shape_var aShape = CreateObject(aTopology);
660 GetCurrentStudy(aStudy->StudyId());
661 const char *anEntry = InsertInLabel(aTopology, aShape->Name(), myCurrentOCAFDoc) ;
662 aShape->ShapeId(anEntry) ;
664 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
665 SALOMEDS::SObject_var aNewSO;
666 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
667 aNewSO = aStudyBuilder->NewObject(theObject);
668 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
669 // Add IORAttribute to the Study and set IOR of the created GEOM_Shape to it
670 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
671 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
672 anIOR->SetValue(aShape->Name());
674 // Return the created in the Study SObject
675 return aNewSO._retn();
678 //============================================================================
679 // function : ComponentDataType()
681 //============================================================================
682 char* GEOM_Gen_i::ComponentDataType()
684 return strdup("GEOM");
687 //============================================================================
688 // function : register()
689 // purpose : register 'name' in 'name_service'
690 //============================================================================
691 void GEOM_Gen_i::register_name(char * name)
693 GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(POA_GEOM::GEOM_Gen::_this());
694 name_service->Register(g, strdup(name));
699 //================================================================================
700 // function : SequenceOfShapeFromListOfGeomShape()
701 // purpose : Define a sequence of shapes from 'listShapes' and return its length.
702 // : No control is made on shapes !
703 //================================================================================
704 int GEOM_Gen_i::SequenceOfShapeFromListOfGeomShape( const GEOM::GEOM_Gen::ListOfGeomShapes& listShapes,
705 TopTools_SequenceOfShape& SS )
707 int nbShapes = listShapes.length() ;
711 for(int i=0; i<nbShapes; i++) {
712 GEOM::GEOM_Shape_var aGeomShape = listShapes[i] ;
713 TopoDS_Shape aShape = GetTopoShape(aGeomShape) ;
722 //=================================================================================
723 // function : GetTopoShape()
724 // purpose : Returns a TopoDS_Shape from a GEOM::GEOM_Shape_ptr in 'myCurrentOCAFDoc'
725 // : A null shape is returned if not possible
726 //=================================================================================
727 TopoDS_Shape GEOM_Gen_i::GetTopoShape(GEOM::GEOM_Shape_ptr shape_ptr)
732 Handle(TDF_Data) D = myCurrentOCAFDoc->GetData() ;
733 TDF_Tool::Label( D, strdup(shape_ptr->ShapeId()), lab, true ) ;
734 Handle(TNaming_NamedShape) NamedShape ;
735 bool res = lab.FindAttribute(TNaming_NamedShape::GetID(), NamedShape) ;
738 return tds ; /* a null shape is returned */
741 return TNaming_Tool::GetShape(NamedShape) ;
747 //=================================================================================
748 // function : GetStringFromIOR()
749 // purpose : returns a string that represents a 'GEOM::GEOM_Shape_var'
750 //=================================================================================
751 const char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Shape_var shapeIOR) {
752 const char * ret = _orb->object_to_string(shapeIOR) ;
758 //=================================================================================
759 // function : GetIORFromString()
760 // purpose : returns a 'GEOM::GEOM_Shape_var' from a string representing it
761 //=================================================================================
762 GEOM::GEOM_Shape_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
763 GEOM::GEOM_Shape_var shapeIOR = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(stringIOR)) ;
769 //==================================================================================
770 // function : InsertInLabel()
771 // purpose : Insert S = Shape and mystr = name in a new Label of Geom/OCAF document
772 // : and returns the corresponding OCAF entry
773 //==================================================================================
774 const char * GEOM_Gen_i::InsertInLabel(TopoDS_Shape S, const char *mystr, Handle(TDocStd_Document) OCAFDoc)
776 GEOMDS_Commands GC(OCAFDoc->Main());
777 /* add attributs S and mystr in a new label */
778 TDF_Label Lab = GC.AddShape (S, strdup(mystr));
780 TCollection_AsciiString entry;
781 TDF_Tool::Entry(Lab,entry);
782 const char *ent = entry.ToCString() ;
787 //==================================================================================
788 // function : InsertInLabelDependentShape()
789 // purpose : Insert S = Shape and its nameIor in a new Label of Geom/OCAF document
790 // : insert also a reference attribute (a label) to the main shape 'mainshap_ptr'.
791 // : and returns the corresponding OCAF entry of the new label.
792 //==================================================================================
793 const char * GEOM_Gen_i::InsertInLabelDependentShape( TopoDS_Shape S,
795 GEOM::GEOM_Shape_ptr mainshape_ptr,
796 Handle(TDocStd_Document) OCAFDoc )
798 GEOMDS_Commands GC(OCAFDoc->Main());
799 /* add attributs S and nameIor in a new label */
801 /* retrieve the label of the main shape in the document */
802 TDF_Label mainRefLab;
803 TDF_Tool::Label(OCAFDoc->GetData(), mainshape_ptr->ShapeId(), mainRefLab);
805 /* add attributs : S, nameIor and ref to main */
806 TDF_Label Lab = GC.AddDependentShape(S, strdup(nameIor), mainRefLab);
808 TCollection_AsciiString entry;
809 TDF_Tool::Entry(Lab, entry);
810 const char *ent = entry.ToCString() ;
815 //=================================================================================
816 // function : InsertInLabelOneArgument()
818 //=================================================================================
819 void GEOM_Gen_i::InsertInLabelOneArgument(TopoDS_Shape main_topo,
820 GEOM::GEOM_Shape_ptr shape_ptr,
821 TopoDS_Shape result_topo,
822 GEOM::GEOM_Shape_ptr result,
823 Handle(TDocStd_Document) OCAFDoc)
825 /* Put shape and name into geom/OCAF doc */
826 GEOMDS_Commands GC(OCAFDoc->Main());
827 /* Add attributs 'shape' and 'name_ior' in a new label */
828 TDF_Label Lab = GC.Generated( main_topo, result_topo, result->Name() );
829 TCollection_AsciiString entry;
830 TDF_Tool::Entry(Lab, entry);
831 result->ShapeId( entry.ToCString() ) ;
833 /* Create a new label */
834 TDF_Label NewLab = Lab.NewChild();
835 TCollection_ExtendedString Value("Arguments");
836 TDataStd_Name::Set(NewLab,Value);
838 TDF_Label NewLab1 = NewLab.NewChild();
840 TDF_Tool::Label(OCAFDoc->GetData(), shape_ptr->ShapeId(), RefLab);
841 TDF_Reference::Set(NewLab1, RefLab);
845 //=================================================================================
846 // function : InsertInLabelMoreArguments()
848 //=================================================================================
849 void GEOM_Gen_i::InsertInLabelMoreArguments(TopoDS_Shape main_topo,
850 GEOM::GEOM_Shape_ptr result,
851 const GEOM::GEOM_Gen::ListOfIOR& ListShapes,
852 Handle(TDocStd_Document) OCAFDoc)
854 /* Put shape and name into geom/OCAF doc */
855 GEOMDS_Commands GC(OCAFDoc->Main());
856 /* Add attributs TopoDS and name_ior in a new label */
857 TDF_Label Lab = GC.AddShape(main_topo, result->Name() );
858 TCollection_AsciiString entry;
859 TDF_Tool::Entry(Lab, entry);
861 /* Create a new label */
862 TDF_Label NewLab = Lab.NewChild();
863 TCollection_ExtendedString Value("Arguments");
864 TDataStd_Name::Set(NewLab, Value);
866 for (unsigned int ind = 0; ind < ListShapes.length(); ind++) {
868 TDF_Label NewLab1 = NewLab.NewChild();
869 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[ind] );
872 TDF_Tool::Label(OCAFDoc->GetData(), aShape->ShapeId(), RefLab);
873 TDF_Reference::Set(NewLab1, RefLab);
875 result->ShapeId(entry.ToCString());
880 //=================================================================================
881 // function: NbLabels()
883 //=================================================================================
884 CORBA::Short GEOM_Gen_i::NbLabels()
886 return TDF_Tool::NbLabels( myCurrentOCAFDoc->Main() );
891 //=================================================================================
892 // function: GetCurrentStudy()
893 // purpose : Finds or creates the geom/OCAF document corresponding to the index
895 //=================================================================================
896 void GEOM_Gen_i::GetCurrentStudy(CORBA::Long StudyID)
898 /* If StudyID is known we link myCurrentOCAFDoc to it */
899 if (myStudyIDToDoc.IsBound(StudyID)) {
900 myCurrentOCAFDoc = Handle(TDocStd_Document)::DownCast(myStudyIDToDoc(StudyID));
902 /* Create a new OCAFDoc and link it to 'StudyID' argument */
904 myOCAFApp->NewDocument("SALOME_GEOM",myCurrentOCAFDoc);
905 myStudyIDToDoc.Bind(StudyID,myCurrentOCAFDoc);
911 //================================================================================
912 // function : CreateObject()
913 // purpose : private function to create a complete CORBA object and return it
914 //================================================================================
915 GEOM::GEOM_Shape_ptr GEOM_Gen_i::CreateObject(TopoDS_Shape& tds)
917 // if ( tds.ShapeType() == TopAbs_COMPOUND ) {
918 // TopoDS_Iterator itr(tds);
921 // while (itr.More()) {
923 // res = itr.Value();
931 GEOM::shape_type st = GEOM::shape_type(tds.ShapeType()) ; /* casting */
933 /* Create the CORBA servant holding the TopoDS_Shape */
934 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
935 GEOM::GEOM_Shape::ListOfSubShapeID_var index = new GEOM::GEOM_Shape::ListOfSubShapeID;
937 GEOM_Shape_i * shape_servant = new GEOM_Shape_i(tds, _orb, engine, index, st, true);
938 GEOM::GEOM_Shape_var shape = GEOM::GEOM_Shape::_narrow(shape_servant->_this());
940 /* Create and set the name (IOR of shape converted into a string) */
941 string name_ior = _orb->object_to_string(shape) ;
942 shape->Name( name_ior.c_str() );
943 shape->NameType( "" );
947 //=======================================================================
948 //function : CreateSubObject
950 //=======================================================================
952 GEOM::GEOM_Shape_ptr GEOM_Gen_i::CreateSubObject(const TopoDS_Shape& SubShape,
953 const GEOM::GEOM_Shape_ptr MainShape,
954 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID)
956 GEOM::shape_type st = GEOM::shape_type(SubShape.ShapeType()) ; /* casting */
958 /* Create the CORBA servant holding the TopoDS_Shape */
959 GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this();
960 GEOM_Shape_i * shape_servant =
961 new GEOM_Shape_i(SubShape, _orb, engine, ListOfID, st, false);
962 GEOM::GEOM_Shape_var shape = GEOM::GEOM_Shape::_narrow(shape_servant->_this());
964 /* Create and set the name (IOR of shape converted into a string) */
965 string name_ior = _orb->object_to_string(shape) ;
966 shape->Name( name_ior.c_str() );
967 /* create and set the mainname (IOR of shape converted into a string) */
968 const char *mainname_ior = _orb->object_to_string(MainShape) ;
969 shape->MainName(mainname_ior);
970 /* precaution : NameType will be set precisely in GUI */
971 shape->NameType( "" );
972 /* add 'SubShape' its 'nameIOR' and a reference to the main shape thanks to method below */
974 InsertInLabelDependentShape(SubShape, shape->Name(), MainShape, myCurrentOCAFDoc) ;
975 shape->ShapeId( entry ) ;
980 //=======================================================================
981 // function : SuppressFacesGlue()
982 // purpose : Define a compound of shells after suppress of mapFaces in the
983 // : shape S and return the number of shells of the compound.
984 //=======================================================================
985 int GEOM_Gen_i::SuppressFacesGlue( const TopoDS_Shape& S,
986 const TopTools_MapOfShape& mapFaces,
987 TopoDS_Shape& aCompoundOfShells )
988 throw (SALOME::SALOME_Exception)
990 BRepTools_Quilt Glue;
991 aCompoundOfShells.Nullify() ;
993 for ( TopExp_Explorer exp( S, TopAbs_FACE); exp.More(); exp.Next() ) {
994 const TopoDS_Face& F = TopoDS::Face(exp.Current());
995 if ( !mapFaces.Contains(F) ) {
996 /* this face must not to be suppressed */
1001 /* Use specif method to calculate the compound of shells */
1002 aCompoundOfShells = Glue.Shells();
1004 if( aCompoundOfShells.ShapeType() != TopAbs_COMPOUND ) {
1005 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SuppressFacesGlue() : not a GEOM::COMPOUND", SALOME::BAD_PARAM);
1008 /* explore Compound for verification and return the number of shells */
1009 int numberOfShell = 0 ;
1010 for ( TopExp_Explorer exp1( aCompoundOfShells, TopAbs_SHELL); exp1.More(); exp1.Next() )
1013 return numberOfShell ;
1017 //=====================================================================================
1018 // function : GetIndexTopology()
1019 // purpose : return the index of a sub shape in a shape (index starts at 1)
1020 // : Return -1 if not found
1021 //=====================================================================================
1022 int GEOM_Gen_i::GetIndexTopology(const TopoDS_Shape& subshape, const TopoDS_Shape& mainShape)
1024 if( mainShape.IsNull() || subshape.IsNull() )
1028 if (subshape.ShapeType() == TopAbs_COMPOUND)
1031 TopTools_ListOfShape CL;
1032 CL.Append( mainShape );
1033 TopTools_ListIteratorOfListOfShape itC;
1034 for (itC.Initialize( CL ); itC.More(); itC.Next())
1036 for (it.Initialize( itC.Value() ); it.More(); it.Next())
1038 if ( it.Value().ShapeType() == TopAbs_COMPOUND)
1040 if (it.Value().IsSame(subshape))
1044 CL.Append( it.Value() );
1051 TopExp_Explorer Exp ( mainShape, subshape.ShapeType() );
1052 TopTools_MapOfShape M;
1053 while ( Exp.More() )
1055 if ( M.Add(Exp.Current()) )
1057 if ( Exp.Current().IsSame(subshape) )
1068 //================================================================================
1069 // function : IndexOfFacesOfSubShell()
1070 // purpose : Return a list of indices corresponding to the faces of a 'subShell'
1071 // : in the main shape 'S'
1072 //================================================================================
1073 GEOM::GEOM_Shape::ListOfSubShapeID* GEOM_Gen_i::IndexOfFacesOfSubShell( const TopoDS_Shape& S,
1074 const TopoDS_Shape subShell )
1075 throw (SALOME::SALOME_Exception)
1078 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
1079 ListOfID->length(0) ;
1080 if( subShell.IsNull() || subShell.ShapeType() != TopAbs_SHELL ) {
1081 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::IndexOfFacesOfSubShell() : null shape or not a GEOM::SHELL", SALOME::BAD_PARAM);
1084 /* put faces of subShell in a Map of faces */
1086 TopTools_MapOfShape mapFaces ;
1087 for( TopExp_Explorer Exp1( subShell, TopAbs_FACE ); Exp1.More(); Exp1.Next() ) {
1088 mapFaces.Add(Exp1.Current() ) ;
1093 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::IndexOfFacesOfSubShell() : no faces in sub shell", SALOME::BAD_PARAM);
1095 /* Find index of each face of subshell in the main topology and put its index in ListOfID */
1097 for ( TopExp_Explorer Exp2(S, TopAbs_FACE); Exp2.More(); Exp2.Next() ) {
1099 const TopoDS_Face& F = TopoDS::Face( Exp2.Current() ) ;
1101 if( mapFaces.Contains(F) ) {
1102 int n = GetIndexTopology( F, S ) ;
1104 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::IndexOfFacesOfSubShell() : no index found", SALOME::BAD_PARAM);
1107 ListOfID->length(size) ;
1108 ListOfID[size-1] = n ;
1112 return ListOfID._retn() ;
1117 //================================================================================
1118 // function : ListOfIDIntoMapOfShapes()
1119 // purpose : Define a MapOfShapes from a main topology 'S' a 'subShapeType'
1120 // : and a list of indices 'L'.
1121 // : Return true if 'aMap' is not empty
1122 //================================================================================
1123 bool GEOM_Gen_i::ListOfIDIntoMapOfShapes( const TopoDS_Shape& S,
1124 const GEOM::GEOM_Shape::ListOfSubShapeID& L,
1125 const int subShapeType,
1126 TopTools_MapOfShape& aMap )
1128 if( L.length() < 1 || S.IsNull() ) {
1133 for( int k=0; k<L.length(); k++ ) {
1134 /* indices start at 1 in list L */
1136 TopExp_Explorer exp ;
1137 TopTools_MapOfShape M;
1138 for( exp.Init( S, TopAbs_ShapeEnum(subShapeType) ); exp.More(); exp.Next() ) {
1139 if ( M.Add(exp.Current()) )
1142 aMap.Add( exp.Current() ) ;
1153 //================================================================================
1154 // function : ListOfIDIntoSequenceOfShapes()
1155 // purpose : Define 'aSequenceOfShapes' from a main topology 'S' a 'subShapeType'
1156 // : and a list of indices 'L'.
1157 // : Return true if 'aSequenceOfShapes' is not empty
1158 //================================================================================
1159 bool GEOM_Gen_i::ListOfIDIntoSequenceOfShapes( const TopoDS_Shape& S,
1160 const GEOM::GEOM_Shape::ListOfSubShapeID& L,
1161 const int subShapeType,
1162 TopTools_SequenceOfShape& aSequenceOfShapes )
1164 if( L.length() < 1 || S.IsNull() ) {
1168 aSequenceOfShapes.Clear() ;
1169 for( int k=0; k<L.length(); k++ ) {
1170 /* indices start at 1 in list L */
1172 TopExp_Explorer exp ;
1173 for( exp.Init( S, TopAbs_ShapeEnum(subShapeType) ); exp.More(); exp.Next() ) {
1175 aSequenceOfShapes.Append( exp.Current() ) ;
1185 //================================================================================
1186 // function : SuppressFaces()
1187 // purpose : Suppress faces contained in ListOfID from 'shape'.
1188 // : Return a list of Geom shapes each one is a main shape GEOM::FACE or GEOM::SHELL
1189 //================================================================================
1190 GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SuppressFaces( GEOM::GEOM_Shape_ptr shape,
1191 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID )
1192 throw (SALOME::SALOME_Exception)
1194 GEOM::GEOM_Gen::ListOfGeomShapes_var listOfGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
1195 listOfGeomShapes->length(0) ;
1197 TopoDS_Shape mainShape = GetTopoShape(shape);
1198 if( mainShape.IsNull() )
1199 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SuppressFaces() : null argument shape", SALOME::BAD_PARAM);
1201 if( ListOfID.length() < 1 )
1202 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SuppressFaces() : empty ListOfID", SALOME::BAD_PARAM);
1204 /* Define 'mapFaces' a map of faces to be suppressed in mainShape */
1205 TopTools_MapOfShape mapFaces ;
1206 if( !ListOfIDIntoMapOfShapes(mainShape, ListOfID, TopAbs_FACE, mapFaces ) ) {
1207 return listOfGeomShapes._retn();
1210 /* Call algorithm to calculate a compound of shells resulting of face suppression */
1211 int numberOfShells = 0 ;
1212 TopoDS_Shape aCompoundOfShells ;
1213 numberOfShells = SuppressFacesGlue(mainShape, mapFaces, aCompoundOfShells) ;
1214 if(numberOfShells < 1) {
1215 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::Suppressfaces() : no shells", SALOME::BAD_PARAM);
1218 /* Create a shell for each shell contained in 'aCompoundOfShells' and */
1219 /* put it in the list of GeomShapes to be returned. */
1220 /* But if the shell is composed of only a face we create a face and not a shell */
1222 for( TopExp_Explorer exp(aCompoundOfShells, TopAbs_SHELL); exp.More(); exp.Next() ) {
1224 const TopoDS_Shell& aShell = TopoDS::Shell( exp.Current() );
1225 if( aShell.IsNull() ) {
1226 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::Suppressfaces() : null shell", SALOME::BAD_PARAM);
1229 GEOM::GEOM_Shape::ListOfSubShapeID_var aList = new GEOM::GEOM_Shape::ListOfSubShapeID;
1230 aList = IndexOfFacesOfSubShell(mainShape, aShell) ;
1232 if( aList->length() < 1 ) {
1233 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SuppressFaces() : aList is empty", SALOME::BAD_PARAM);
1236 TopoDS_Shape aShellOrFace ;
1237 /* Only a face into the shell : we create a single face instead of a shell : 'aList' is unchanged */
1238 if( aList->length() == 1 ) {
1239 TopExp_Explorer exp ;
1240 exp.Init( aShell, TopAbs_FACE ) ;
1242 aShellOrFace = exp.Current() ;
1245 aShellOrFace = aShell ;
1248 /* Create CORBA object */
1249 GEOM::GEOM_Shape_var result = CreateObject(aShellOrFace) ;
1250 if( CORBA::is_nil(result) ) {
1251 THROW_SALOME_CORBA_EXCEPTION("Suppress Faces aborted : null result", SALOME::BAD_PARAM);
1254 InsertInLabelOneArgument(mainShape, shape, aShellOrFace, result, myCurrentOCAFDoc) ;
1256 listOfGeomShapes->length(i) ;
1257 listOfGeomShapes[i-1] = result ;
1260 return listOfGeomShapes._retn() ;
1265 //================================================================================
1266 // function : IsShapeInSequence()
1267 // purpose : return true is aShape is in SS. The test method is 'IsSame()'
1268 //================================================================================
1269 bool GEOM_Gen_i::IsShapeInSequence(const TopTools_SequenceOfShape& SS, const TopoDS_Shape& aShape)
1271 if( aShape.IsNull() || SS.IsEmpty() )
1273 for( int i=1; i<=SS.Length(); i++) {
1274 if( SS.Value(i).IsSame(aShape) )
1281 //================================================================================
1282 // function : FreeEdgesFromMapOfFace()
1283 // purpose : Define MS a map of all edges of faces of 'MSfaces'
1284 // : All multiple edges are removed !
1285 //================================================================================
1286 void GEOM_Gen_i::FreeEdgesFromMapOfFace( const TopTools_MapOfShape& MSfaces,
1287 TopTools_MapOfShape& MS )
1290 TopTools_MapOfShape Multiple ;
1291 TopTools_MapIteratorOfMapOfShape it ;
1292 for( it.Initialize(MSfaces); it.More(); it.Next() ) {
1293 TopoDS_Shape aFace = it.Key() ;
1294 TopExp_Explorer exp ;
1295 for( exp.Init( aFace, TopAbs_EDGE); exp.More(); exp.Next() ) {
1296 if( !Multiple.Contains( exp.Current() ) && !MS.Add( exp.Current() ) ) {
1297 MS.Remove( exp.Current() ) ;
1298 Multiple.Add( exp.Current() ) ;
1306 //================================================================================
1307 // function : MapRemoveSequence()
1308 // purpose : In term of shapes ST = MS - SSRemove
1310 //================================================================================
1311 void GEOM_Gen_i::MapRemoveSequence( const TopTools_MapOfShape& MS,
1312 const TopTools_SequenceOfShape& SSRemove,
1313 TopTools_SequenceOfShape& ST )
1316 TopTools_MapIteratorOfMapOfShape it ;
1317 for( it.Initialize(MS); it.More(); it.Next() ) {
1318 TopoDS_Shape aShape = it.Key() ;
1319 if( !IsShapeInSequence( SSRemove, aShape ) )
1320 ST.Append( aShape ) ;
1327 //================================================================================
1328 // function : SuppressHoleSubRoutine()
1329 // purpose : Define recursively 'MSfacesSuppress' a list of faces to suppress in a hole
1330 //================================================================================
1331 void GEOM_Gen_i::SuppressHoleSubRoutine( const TopoDS_Shape& mainShape,
1332 const TopoDS_Face& aFace,
1333 const TopTools_SequenceOfShape& SSedgesOfWire,
1334 const TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgesFaces,
1335 const TopTools_MapOfShape& MSfaces,
1336 TopTools_MapOfShape& MSfacesSuppress,
1337 const Standard_Boolean withEndFace,
1338 const TopoDS_Face& endFace,
1339 TopTools_MapOfShape& MSwireEndEdges )
1340 throw (SALOME::SALOME_Exception)
1342 TopTools_MapOfShape MS ;
1343 TopTools_SequenceOfShape SU ;
1344 FreeEdgesFromMapOfFace(MSfaces, MS) ; /* MS = free edges of MSfaces */
1345 MapRemoveSequence(MS, SSedgesOfWire, SU) ; /* SU = MS - SSedgesOfWire */
1347 if( SU.IsEmpty() ) {
1351 /* Here SU contains new edges to find new faces to suppress */
1352 /* Define the list of faces of SU edges that aren't in faces of MSfacesSuppress in order to add into */
1353 /* For each edge we have a map of all its faces : it's in 'aMapEdgesFaces' */
1354 TopTools_MapOfShape MSfacesTmp ;
1355 for( int v=1; v<=SU.Length(); v++ ) {
1356 TopoDS_Shape E = SU.Value(v) ;
1358 TopTools_ListOfShape LF ;
1359 int ind = aMapEdgesFaces.FindIndex(E) ;
1361 /* LF is the list of faces for an edge of SU : may be empty no matter */
1362 LF = aMapEdgesFaces.FindFromIndex(ind) ;
1364 TopTools_ListIteratorOfListOfShape it ;
1365 for( it.Initialize(LF); it.More(); it.Next() ) {
1367 if( withEndFace == false ) {
1368 if( F.IsSame(aFace) )
1369 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHoleSubRoutine() : hole traversing or ?", SALOME::BAD_PARAM);
1370 if( !MSfacesSuppress.Contains(F) ) {
1371 MSfacesSuppress.Add(F) ;
1372 MSfacesTmp.Add(F) ; // Dont remove the 'if' !
1375 else { /* withEndFace == true */
1376 if( F.IsSame(aFace) && !F.IsSame(endFace) )
1377 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHoleSubRoutine() : hole traversing incoherent ?", SALOME::BAD_PARAM);
1379 if( F.IsSame(endFace) ) {
1380 /* We have reached endFace if selection was correct so we add */
1381 /* edge in a map to find later the corresponding endWire (hole */
1382 MSwireEndEdges.Add(E) ;
1385 if( !MSfacesSuppress.Contains(F) ) {
1386 MSfacesSuppress.Add(F) ;
1393 /* Call recursively this routine */
1394 SuppressHoleSubRoutine( mainShape, aFace, SSedgesOfWire, aMapEdgesFaces, MSfacesTmp, MSfacesSuppress, withEndFace, endFace, MSwireEndEdges ) ;
1399 //================================================================================
1400 // function : GetShapeFromIndex()
1401 // purpose : Find 'tds' a sub shape of 'aShape' according to 'aList' that contains
1402 // : a unique index !
1403 // : Warning : index must be setted with the same exploration logic !
1404 // : So 'index' is calculated with no shape doublons !
1405 //================================================================================
1406 bool GEOM_Gen_i::GetShapeFromIndex( const TopoDS_Shape& aShape,
1407 const TopAbs_ShapeEnum aType,
1412 if (aShape.IsNull() || index < 1)
1414 /* Indices start at 1 */
1416 bool found = false ;
1417 TopExp_Explorer exp ;
1418 TopTools_MapOfShape M;
1419 for( exp.Init( aShape, aType ); exp.More(); exp.Next() ) {
1420 if( M.Add(exp.Current()) ) { /* if not a doublon : we compare */
1422 tds = exp.Current() ;
1433 //================================================================================
1434 // function : SuppressHolesInFaceOrShell() Main method.
1435 // purpose : Suppress holes identified by wires in a single face or shell
1437 //================================================================================
1438 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHolesInFaceOrShell( GEOM::GEOM_Shape_ptr shapeFaceShell,
1439 const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdWires )
1440 throw (SALOME::SALOME_Exception)
1442 GEOM::GEOM_Shape_var result;
1444 if( ListIdWires.length() < 1 )
1445 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace : no holes selected", SALOME::BAD_PARAM);
1447 const TopoDS_Shape tds = GetTopoShape(shapeFaceShell) ;
1448 if( tds.IsNull() || !BRepAlgoAPI::IsValid(tds) )
1449 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace() : non valid main argument", SALOME::BAD_PARAM);
1451 /* Create a map of wires/holes to suppress */
1452 TopTools_MapOfShape MapHoles ;
1453 for ( int i = 0; i < ListIdWires.length(); i++ ) {
1455 if( !GetShapeFromIndex( tds, TopAbs_WIRE, ListIdWires[i], W ) )
1456 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace() : bad index ?", SALOME::BAD_PARAM);
1460 /* Test if argument is a face or shell */
1462 if( tds.ShapeType() == TopAbs_FACE )
1464 else if ( tds.ShapeType() == TopAbs_SHELL )
1467 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace() : not a face or a shell", SALOME::BAD_PARAM);
1469 /* Define two maps : all faces and faces to that will be modified */
1470 TopTools_MapOfShape MapFacesToModify ;
1471 TopTools_MapOfShape MapFacesAll ;
1472 TopExp_Explorer expF ;
1473 for( expF.Init( tds, TopAbs_FACE); expF.More(); expF.Next() ) {
1474 TopoDS_Face F = TopoDS::Face( expF.Current() ) ;
1475 MapFacesAll.Add(F) ;
1476 TopExp_Explorer expW ;
1477 for( expW.Init( F, TopAbs_WIRE); expW.More(); expW.Next() ) {
1478 TopoDS_Wire W = TopoDS::Wire( expW.Current() ) ;
1479 if( MapHoles.Contains(W) ) {
1480 MapFacesToModify.Add(F) ;
1485 /* Define faces not modified */
1486 TopTools_MapOfShape MapFacesNotModified ;
1487 TopTools_MapIteratorOfMapOfShape it ;
1488 for( it.Initialize(MapFacesAll); it.More(); it.Next() ) {
1489 TopoDS_Face FF = TopoDS::Face( it.Key() ) ;
1490 if( !MapFacesToModify.Contains(FF) )
1491 MapFacesNotModified.Add(FF) ;
1494 if( MapFacesToModify.IsEmpty() )
1495 THROW_SALOME_CORBA_EXCEPTION("Error : empty map of faces", SALOME::BAD_PARAM);
1497 if( isFace && MapFacesToModify.Extent() != 1 )
1498 THROW_SALOME_CORBA_EXCEPTION("Incoherent", SALOME::BAD_PARAM);
1500 /* Main argument is a face */
1501 if( isFace && MapFacesToModify.Extent() == 1 ) {
1502 TopoDS_Face resultFace ;
1503 if( !RebuildFaceRemovingHoles( TopoDS::Face(tds), MapHoles, resultFace ) )
1504 THROW_SALOME_CORBA_EXCEPTION(" Problem : !RebuildFaceRemovingHoles()", SALOME::BAD_PARAM);
1505 /* Creation of CORBA object : face topology */
1506 result = CreateObject(resultFace);
1507 InsertInLabelOneArgument(tds, shapeFaceShell, resultFace, result, myCurrentOCAFDoc) ;
1511 /* Main argument is a shell : rebuild faces modified */
1512 TopTools_MapOfShape MapFacesModified ;
1513 for( it.Initialize(MapFacesToModify); it.More(); it.Next() ) {
1514 TopoDS_Face FF = TopoDS::Face( it.Key() ) ;
1516 if( !RebuildFaceRemovingHoles( FF, MapHoles, resF ) )
1517 THROW_SALOME_CORBA_EXCEPTION(" Problem shell : !RebuildFaceRemovingHoles()", SALOME::BAD_PARAM);
1518 MapFacesModified.Add(resF) ;
1521 /* Rebuild the shell with faces modified and non modified */
1522 TopoDS_Shell resultShell ;
1524 B.MakeShell(resultShell) ;
1525 TopTools_MapIteratorOfMapOfShape it1 ;
1526 for( it1.Initialize(MapFacesModified); it1.More(); it1.Next() )
1527 B.AddShellFace( resultShell,TopoDS::Face( it1.Key() ) ) ;
1528 for( it1.Initialize(MapFacesNotModified); it1.More(); it1.Next() )
1529 B.AddShellFace( resultShell,TopoDS::Face( it1.Key() ) ) ;
1531 B.CompleteShell(resultShell) ;
1533 if( resultShell.IsNull() )
1534 THROW_SALOME_CORBA_EXCEPTION("Null or not valid result Shell", SALOME::BAD_PARAM) ;
1536 /* Creation of CORBA object : shell topology */
1537 result = CreateObject(resultShell);
1538 InsertInLabelOneArgument(tds, shapeFaceShell, resultShell, result, myCurrentOCAFDoc) ;
1543 //================================================================================
1544 // function : RebuildFaceRemovingHoles()
1545 // purpose : Rebuild a face removing holes that are in 'mapHoles'.
1546 // : NB : 'mapHoles' may content more holes than necessary
1547 //================================================================================
1548 bool GEOM_Gen_i::RebuildFaceRemovingHoles( const TopoDS_Face& aFace,
1549 const TopTools_MapOfShape& mapHoles,
1550 TopoDS_Shape& resultFace )
1552 /* Get the outer wire of the face 'aFace' */
1553 TopoDS_Wire outW = BRepTools::OuterWire( aFace ) ;
1554 if( outW.IsNull() || !BRepAlgoAPI::IsValid(outW) )
1555 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace : bad outer wire of 'aFace'", SALOME::BAD_PARAM);
1557 /* Rebuild a face avoiding holes in the map 'mapHoles' */
1558 Handle(Geom_Surface) Surface = BRep_Tool::Surface(aFace) ;
1559 TopoDS_Face F2 = BRepBuilderAPI_MakeFace( Surface, outW, true ) ;
1561 if( F2.Orientation() != aFace.Orientation() )
1562 F2.Orientation( aFace.Orientation() ) ;
1564 BRepBuilderAPI_MakeFace aBuilder( F2 ) ;
1565 bool foundAndKeepHoles = false ;
1566 TopExp_Explorer exp ;
1568 for( exp.Init( aFace, TopAbs_WIRE); exp.More(); exp.Next() ) {
1569 TopoDS_Wire hole = TopoDS::Wire( exp.Current() ) ;
1570 if( !mapHoles.Contains(hole) && !exp.Current().IsEqual(outW) ) {
1571 aBuilder.Add( hole) ;
1572 if( !aBuilder.IsDone() )
1573 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace : builder problem !", SALOME::BAD_PARAM);
1575 resultFace = TopoDS::Face(aBuilder) ;
1576 foundAndKeepHoles = true ;
1580 if( !foundAndKeepHoles )
1583 resultFace = TopoDS::Face(aBuilder) ;
1591 //================================================================================
1592 // function : SuppressHole() Main method.
1593 // purpose : Suppress an hole identified by a wire in a face of shape
1594 // : ListIdFace contains a unique index of face in shape
1595 // : ListIdWire contains a unique index of wire in face !!!
1596 // : ListIdEndFace is used only when hole traverse.
1597 //================================================================================
1598 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHole( GEOM::GEOM_Shape_ptr shape,
1599 const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdFace,
1600 const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdWire,
1601 const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdEndFace )
1602 throw (SALOME::SALOME_Exception)
1604 GEOM::GEOM_Shape_var result;
1607 TopoDS_Face endFace ;
1611 /* Retrieve 'aShape' the initial main shape selection */
1612 const TopoDS_Shape aShape = GetTopoShape(shape);
1614 if( !BRepAlgoAPI::IsValid(aShape) )
1615 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : non valid main shape", SALOME::BAD_PARAM);
1617 if( ListIdFace.length() != 1 || ListIdWire.length() != 1 )
1618 THROW_SALOME_CORBA_EXCEPTION("bad list", SALOME::BAD_PARAM);
1620 /* Retrieve 'aFace' selection */
1621 if( !GetShapeFromIndex( aShape, TopAbs_FACE, ListIdFace[0], tmp ) ) {
1622 THROW_SALOME_CORBA_EXCEPTION("face not found", SALOME::BAD_PARAM);
1625 aFace = TopoDS::Face(tmp) ;
1627 if( !BRepAlgoAPI::IsValid(aFace) )
1628 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : face shape not valid", SALOME::BAD_PARAM);
1630 /* Retrieve 'aWire' selection : Warning : index of wire refers to the face ! */
1632 if( !GetShapeFromIndex( aFace, TopAbs_WIRE, ListIdWire[0], aTmp ) ) {
1633 THROW_SALOME_CORBA_EXCEPTION("wire not found", SALOME::BAD_PARAM);
1636 aWire = TopoDS::Wire(aTmp) ;
1638 if( !BRepAlgoAPI::IsValid(aWire) )
1639 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : bad wire" , SALOME::BAD_PARAM);
1641 /* Get the outer wire of aFace */
1642 TopoDS_Wire outerW = BRepTools::OuterWire( aFace ) ;
1643 if( outerW.IsNull() || !BRepAlgoAPI::IsValid(outerW) )
1644 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : bad outer wire", SALOME::BAD_PARAM);
1646 /* Test bad user selection aWire */
1647 if( aWire.IsSame(outerW) )
1648 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : outerW = aWire", SALOME::BAD_PARAM);
1650 /* Test if 'endFace' is used as argument and seems to be a valid one */
1651 /* NB : 'endFace' is optional and used when hole to suppress traverse 'aShape' */
1652 if( ListIdEndFace.length() == 0 ) {
1653 withEndFace = false ;
1656 TopoDS_Shape aTemp ;
1657 if( !GetShapeFromIndex( aShape, TopAbs_FACE, ListIdEndFace[0], aTemp ) || tmp.IsNull() || !BRepAlgoAPI::IsValid(aTemp) )
1658 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : non valid endFace", SALOME::BAD_PARAM);
1660 /* Test if 'endFace' as at least one hole */
1661 endFace = TopoDS::Face(aTemp) ;
1663 TopExp_Explorer fExp ;
1665 for( fExp.Init(endFace, TopAbs_WIRE); fExp.More(); fExp.Next() ) {
1666 TopoDS_Wire W = TopoDS::Wire( fExp.Current() ) ;
1667 if( !W.IsNull() && BRepAlgoAPI::IsValid(W) )
1671 withEndFace = true ; /* at least 2 wires : outer wire plus an hole or more */
1673 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : end face selection ?", SALOME::BAD_PARAM);
1676 /* Find edges of aWire and test if degenerated */
1677 TopTools_SequenceOfShape SSedgesOfWire ;
1678 TopExp_Explorer wireExp ;
1679 for( wireExp.Init(aWire, TopAbs_EDGE); wireExp.More(); wireExp.Next() ) {
1680 TopoDS_Edge E = TopoDS::Edge( wireExp.Current() ) ;
1681 if( E.IsNull() || BRep_Tool::Degenerated(E) ) {
1682 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : found bad edge", SALOME::BAD_PARAM);
1685 SSedgesOfWire.Append( wireExp.Current() ) ;
1688 if( SSedgesOfWire.Length() < 1 )
1689 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : no edge(s) for aWire", SALOME::BAD_PARAM);
1691 /* Retrieve face ancestors of all edges of 'aWire' but avoiding 'aFace' */
1693 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgesFaces;
1694 TopTools_MapIteratorOfMapOfShape anIt ;
1695 TopTools_MapOfShape MFSuppress ;
1696 TopTools_MapOfShape MFSuppressTmp ;
1697 bool wireOnFace = false ;
1699 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aMapEdgesFaces) ;
1700 for( int h=1; h<=SSedgesOfWire.Length(); h++ ) {
1702 TopoDS_Shape anEdgeOfWire = SSedgesOfWire.Value(h) ;
1703 int ind = aMapEdgesFaces.FindIndex(anEdgeOfWire) ;
1705 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : index of edge", SALOME::BAD_PARAM);
1707 TopTools_ListOfShape LF;
1708 LF = aMapEdgesFaces.FindFromIndex(ind) ; /* Contains all faces ancestors of an edge of wire */
1710 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : no face for an edge", SALOME::BAD_PARAM);
1712 /* Filter faces avoiding 'aFace' */
1713 TopTools_ListIteratorOfListOfShape it ;
1714 for( it.Initialize(LF); it.More(); it.Next() ) {
1715 TopoDS_Face F = TopoDS::Face( it.Value() ) ;
1716 if( !F.IsSame(aFace) ) {
1717 MFSuppressTmp.Add(F) ;
1727 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : wire not on selected face", SALOME::BAD_PARAM);
1730 /* Call routine to define faces to suppress and and optional endWire on endFace */
1731 TopTools_MapOfShape MSwireEndEdges ; /* will contain edges of final wire (hole) */
1732 SuppressHoleSubRoutine( aShape, aFace, SSedgesOfWire, aMapEdgesFaces, MFSuppressTmp, MFSuppress, withEndFace, endFace, MSwireEndEdges ) ;
1734 TopoDS_Wire endWire ;
1737 if( MSwireEndEdges.Extent() < 1 )
1738 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : MSwireEndEdges.Extent() < 1", SALOME::BAD_PARAM);
1740 if( !FindCompareWireHoleOnFace( endFace, MSwireEndEdges, endWire ) )
1741 THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SupressHole() : no endWire found", SALOME::BAD_PARAM);
1744 /* Build 'resTds' : a shape containing a compound of faces */
1745 TopoDS_Shape resTds;
1746 if( !withEndFace && !BuildShapeHoleNotTraversing( aShape, aFace, aWire, MFSuppress, resTds ) )
1747 THROW_SALOME_CORBA_EXCEPTION("Rebuild result shape has aborted", SALOME::BAD_PARAM);
1749 if( withEndFace && !BuildShapeHoleTraversing( aShape, aFace, aWire, MFSuppress, endFace, endWire, resTds ) )
1750 THROW_SALOME_CORBA_EXCEPTION("Rebuild result shape has aborted (end hole)", SALOME::BAD_PARAM);
1752 /* Reconstruction of final shape with 'resTds' : a compound of faces after hole suppressing */
1753 /* Actual limitation is : 'aShape' must not contain more than a solid or a shell ! */
1754 TopoDS_Shape finalShape ;
1756 TopExp_Explorer exp ;
1757 unsigned int nbSolid = 0 ;
1758 TopoDS_Solid aSolid ;
1759 for( exp.Init(aShape, TopAbs_SOLID); exp.More(); exp.Next() ) {
1760 aSolid = TopoDS::Solid( exp.Current() ) ;
1763 THROW_SALOME_CORBA_EXCEPTION("Limitation : main shape contents more than one solid", SALOME::BAD_PARAM);
1766 unsigned int nbShell = 0 ;
1767 TopoDS_Shell aShell ;
1768 for( exp.Init(aShape, TopAbs_SHELL); exp.More(); exp.Next() ) {
1769 aShell = TopoDS::Shell( exp.Current() ) ;
1772 THROW_SALOME_CORBA_EXCEPTION("Limitation : main shape contents more than one shell", SALOME::BAD_PARAM);
1775 /* No shells and no solids : can send a compound even for a single face, see GUI ! */
1776 if( nbShell == 0 ) {
1777 finalShape = resTds ;
1781 TopoDS_Shell shellResult ;
1782 if( nbShell == 1 ) {
1783 if ( !BuildShellWithFaceCompound( TopoDS::Compound(resTds), shellResult ) )
1784 THROW_SALOME_CORBA_EXCEPTION("Error after BuildShellWithFaceCompound()", SALOME::BAD_PARAM);
1785 finalShape = shellResult ;
1788 /* a solid with a shell */
1789 if( nbSolid == 1 && nbShell == 1) {
1790 BRepBuilderAPI_MakeSolid B;
1791 B.Add(shellResult) ;
1793 THROW_SALOME_CORBA_EXCEPTION("Error : !B.IsDone()", SALOME::BAD_PARAM);
1794 finalShape = B.Solid() ;
1797 result = CreateObject(finalShape);
1798 InsertInLabelOneArgument(aShape, shape, finalShape, result, myCurrentOCAFDoc) ;
1804 //================================================================================
1805 // function : BuildShellWithFaceCompound()
1806 // purpose : Build a shell with a compound of faces.
1807 //================================================================================
1808 bool GEOM_Gen_i::BuildShellWithFaceCompound( const TopoDS_Compound Comp,
1809 TopoDS_Shell& resultShell )
1811 resultShell.Nullify() ;
1812 BRepPrim_Builder B ;
1813 B.MakeShell(resultShell) ;
1814 TopExp_Explorer ex ;
1816 for( ex.Init( Comp, TopAbs_FACE); ex.More(); ex.Next() ) {
1817 TopoDS_Face F = TopoDS::Face( ex.Current() ) ;
1818 if( !BRepAlgoAPI::IsValid(F) ) {
1821 B.AddShellFace( resultShell, F ) ;
1823 B.CompleteShell(resultShell) ;
1824 if( resultShell.IsNull() ) {
1831 //================================================================================
1832 // function : FindCompareWireHoleOnFace()
1833 // purpose : Try to find a wire on 'aFace' which edges are same than those
1834 // : into 'MSwireEdges' map. 'aFoundWire' is defined and 'true' returned.
1835 // : 'MSwireEdges' represents generally an hole an 'aFace'.
1836 // : The outer wire of 'aFace' is avoided !
1837 //================================================================================
1838 bool GEOM_Gen_i::FindCompareWireHoleOnFace( const TopoDS_Face& F,
1839 const TopTools_MapOfShape& MSwireEdges,
1840 TopoDS_Wire& aFoundWire )
1842 aFoundWire.Nullify() ;
1847 /* Get the outer wire of aFace */
1848 TopoDS_Wire outerW = BRepTools::OuterWire(F) ;
1849 if( outerW.IsNull() || !BRepAlgoAPI::IsValid(outerW) ) {
1853 int nbEdges = MSwireEdges.Extent() ;
1858 TopExp_Explorer exp1 ;
1859 TopExp_Explorer exp2 ;
1860 for ( exp1.Init(F, TopAbs_WIRE) ; exp1.More(); exp1.Next() ) {
1861 TopoDS_Wire W = TopoDS::Wire( exp1.Current() ) ;
1863 if( !W.IsSame(outerW) ) {
1864 for ( exp2.Init( W, TopAbs_EDGE) ; exp2.More(); exp2.Next() ) {
1865 TopoDS_Edge E = TopoDS::Edge( exp2.Current() ) ;
1866 if( MSwireEdges.Contains(E) ) {
1868 if( i == nbEdges ) {
1880 //================================================================================
1881 // function : BuildShapeHoleNotTraversing()
1882 // purpose : Define 'resultTds' a reconstruction of 'aShape' after modification
1883 // : on 'aFace' where 'aWire is removed' and suppression of faces 'MFSuppress'
1884 // : ( Used as a sub routine of SuppressHole() )
1885 //================================================================================
1886 bool GEOM_Gen_i::BuildShapeHoleNotTraversing( const TopoDS_Shape& aShape,
1887 const TopoDS_Face& aFace,
1888 const TopoDS_Wire& aWire,
1889 const TopTools_MapOfShape& MFSuppress,
1890 TopoDS_Shape& resultTds )
1891 throw (SALOME::SALOME_Exception)
1894 TopExp_Explorer exp ;
1895 TopoDS_Face newFace ;
1897 resultTds.Nullify() ;
1898 TopoDS_Compound Comp ;
1899 B.MakeCompound (Comp);
1903 /* Explore all faces of 'aShape' to rebuild a compound */
1904 for ( exp.Init(aShape, TopAbs_FACE) ; exp.More(); exp.Next() ) {
1906 TopoDS_Face F1 = TopoDS::Face( exp.Current() );
1907 /* Rebuild face(s) not suppressed */
1908 if( !MFSuppress.Contains(F1) ) {
1910 if( F1.IsEqual( aFace ) ) {
1911 TopTools_MapOfShape MSwire ;
1913 if( !RebuildFaceRemovingHoles(aFace, MSwire, newFace) ) {
1916 B.Add( Comp, newFace ) ;
1919 /* For any other face not suppressed */
1925 catch(Standard_Failure) {
1926 THROW_SALOME_CORBA_EXCEPTION("in BuildShapeHoleNotTraversing() : Exception catched", SALOME::BAD_PARAM);
1934 //================================================================================
1935 // function : BuildShapeHoleTraversing()
1936 // purpose : Define 'resultTds' a reconstruction of 'aShape' after modifications.
1937 // : On 'aFace' 'aWire is removed'
1938 // : On 'endFace' 'endWire' is removed.
1939 // : Faces of 'MFSuppress' are removed.
1940 // : ( Used as a sub routine of SuppressHole() )
1941 //================================================================================
1942 bool GEOM_Gen_i::BuildShapeHoleTraversing( const TopoDS_Shape& aShape,
1943 const TopoDS_Face& aFace,
1944 const TopoDS_Wire& aWire,
1945 const TopTools_MapOfShape& MFSuppress,
1946 const TopoDS_Face& endFace,
1947 const TopoDS_Wire& endWire,
1948 TopoDS_Shape& resultTds )
1949 throw (SALOME::SALOME_Exception)
1952 TopExp_Explorer exp ;
1953 TopoDS_Face newFace ;
1955 resultTds.Nullify() ;
1956 TopoDS_Compound Comp ;
1957 B.MakeCompound (Comp);
1959 /* Necessary to use general method */
1960 TopTools_MapOfShape MSwire1 ;
1961 MSwire1.Add(aWire) ;
1962 TopTools_MapOfShape MSwire2 ;
1963 MSwire2.Add(endWire) ;
1967 /* Explore all faces of 'aShape' to rebuild a compound */
1968 for ( exp.Init(aShape, TopAbs_FACE) ; exp.More(); exp.Next() ) {
1969 TopoDS_Face F1 = TopoDS::Face( exp.Current() );
1971 /* Rebuild face(s) not suppressed */
1972 if( !MFSuppress.Contains(F1) ) {
1974 /* Rebuild 'aFace' */
1975 if( F1.IsEqual( aFace ) && !F1.IsEqual( endFace ) ) {
1976 if( !RebuildFaceRemovingHoles(aFace, MSwire1, newFace) ) {
1979 B.Add(Comp, newFace) ;
1982 /* Rebuild 'endFace' */
1983 if( !F1.IsEqual( aFace ) && F1.IsEqual( endFace ) ) {
1984 if( !RebuildFaceRemovingHoles(endFace, MSwire2, newFace) ) {
1987 B.Add(Comp, newFace) ;
1990 /* Hole in the same face : aFace = endFace */
1991 if( F1.IsEqual( aFace ) && F1.IsEqual( endFace ) ) {
1993 if( !RebuildFaceRemovingHoles(aFace, MSwire1, newFace) || !RebuildFaceRemovingHoles(newFace, MSwire2, FF) ) {
1999 /* For any other face not suppressed */
2000 if( !F1.IsEqual(aFace) && !F1.IsEqual( endFace ) ) {
2007 catch(Standard_Failure) {
2008 THROW_SALOME_CORBA_EXCEPTION("in BuildShapeHoleTraversing() : Exception catched", SALOME::BAD_PARAM);
2014 //=======================================================================
2015 //function : SortShapes
2017 //=======================================================================
2019 static void SortShapes(TopTools_ListOfShape& SL)
2021 Standard_Integer MaxShapes = SL.Extent();
2022 TopTools_Array1OfShape aShapes (1,MaxShapes);
2023 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
2024 TColStd_Array1OfReal MidXYZ (1,MaxShapes); //X,Y,Z;
2025 TColStd_Array1OfReal Length (1,MaxShapes); //X,Y,Z;
2027 // Computing of CentreOfMass
2028 Standard_Integer Index;
2031 TopTools_ListIteratorOfListOfShape it(SL);
2032 for (Index=1; it.More(); Index++)
2034 TopoDS_Shape S = it.Value();
2035 SL.Remove( it ); // == it.Next()
2037 OrderInd.SetValue (Index, Index);
2038 if (S.ShapeType() == TopAbs_VERTEX)
2040 GPoint = BRep_Tool::Pnt( TopoDS::Vertex( S ));
2041 Length.SetValue( Index, (Standard_Real) S.Orientation());
2045 BRepGProp::LinearProperties (S, GPr);
2046 GPoint = GPr.CentreOfMass();
2047 Length.SetValue( Index, GPr.Mass() );
2049 MidXYZ.SetValue(Index,
2050 GPoint.X()*999 + GPoint.Y()*99 + GPoint.Z()*0.9);
2053 Standard_Integer aTemp;
2054 Standard_Boolean exchange, Sort = Standard_True;
2057 Sort = Standard_False;
2058 for (Index=1; Index < MaxShapes; Index++)
2060 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1)))
2061 exchange = Standard_True;
2062 else if (MidXYZ(OrderInd(Index)) == MidXYZ(OrderInd(Index+1)) &&
2063 Length(OrderInd(Index)) > Length(OrderInd(Index+1)) )
2064 exchange = Standard_True;
2066 exchange = Standard_False;
2069 aTemp = OrderInd(Index);
2070 OrderInd(Index) = OrderInd(Index+1);
2071 OrderInd(Index+1) = aTemp;
2072 Sort = Standard_True;
2076 for (Index=1; Index <= MaxShapes; Index++)
2077 SL.Append( aShapes( OrderInd(Index) ));
2080 //================================================================================
2081 // function : SubShape()
2082 // purpose : Method for GUI or TUI
2083 //================================================================================
2085 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShape(GEOM::GEOM_Shape_ptr shape,
2086 CORBA::Short ShapeType,
2087 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID)
2088 throw (SALOME::SALOME_Exception)
2090 return SubShapesOne(shape, (TopAbs_ShapeEnum) ShapeType, ListOfID);
2093 //================================================================================
2094 // function : SubShapeSorted()
2095 // purpose : Method for GUI or TUI
2096 //================================================================================
2098 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShapeSorted(GEOM::GEOM_Shape_ptr shape,
2099 CORBA::Short ShapeType,
2100 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID)
2101 throw (SALOME::SALOME_Exception)
2103 return SubShapesOne(shape, (TopAbs_ShapeEnum) ShapeType, ListOfID, Standard_True);
2106 //================================================================================
2107 // function : SubShapesOne()
2109 //================================================================================
2111 GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShapesOne( GEOM::GEOM_Shape_ptr shape,
2112 const TopAbs_ShapeEnum ShapeType,
2113 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID,
2114 const Standard_Boolean Sort)
2115 throw (SALOME::SALOME_Exception)
2117 GEOM::GEOM_Shape_var result;
2118 TopoDS_Shape mainShape;
2119 TopoDS_Shape mainTopo = GetTopoShape(shape);
2123 if ( shape->IsMainShape() ) {
2124 mainShape = GetTopoShape(shape);
2127 shape = GetIORFromString( shape->MainName() );
2130 if(ListOfID.length() < 1) {
2131 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SubShape() : bad list of shapes",
2135 /* Create a sequence of all sub shapes */
2136 TopTools_ListOfShape listShape;
2138 TopTools_MapOfShape mapShape;
2139 TopExp_Explorer exp ;
2140 for ( exp.Init( mainShape, TopAbs_ShapeEnum(ShapeType)) ; exp.More(); exp.Next() ) {
2141 if ( mapShape.Add( exp.Current() ) )
2142 listShape.Append ( exp.Current() );
2145 if (listShape.IsEmpty()) return shape;
2148 SortShapes(listShape);
2150 TopTools_SequenceOfShape SS;
2151 TopTools_ListIteratorOfListOfShape it (listShape);
2152 for (; it.More(); it.Next())
2153 SS.Append( it.Value() );
2155 TopoDS_Shape SubShape;
2156 if (ListOfID.length() == 1)
2157 SubShape = SS.Value(ListOfID[0]);
2161 TopoDS_Compound Comp;
2162 B.MakeCompound (Comp);
2164 for ( ind = 0; ind < ListOfID.length(); ind++ )
2165 B.Add( Comp, SS.Value(ListOfID[ind]) );
2169 if ( !TNaming_Tool::HasLabel( myCurrentOCAFDoc->Main(), SubShape ) )
2170 result = CreateSubObject( SubShape, shape, ListOfID);
2173 TDF_Label Lab = TNaming_Tool::Label( myCurrentOCAFDoc->Main(), SubShape, TransDef );
2174 Handle(TDataStd_Name) Att;
2175 if ( Lab.FindAttribute( TDataStd_Name::GetID(), Att ) ) {
2176 TCollection_AsciiString nameIOR( Att->Get() );
2177 result = GEOM::GEOM_Shape::_narrow(_orb->string_to_object( nameIOR.ToCString() ));
2178 if ( strcmp( result->MainName(), _orb->object_to_string(shape) ) != 0 ) {
2179 result = CreateSubObject( SubShape, shape, ListOfID);
2188 //================================================================================
2189 // function : SubShapeAll()
2190 // purpose : Explode a shape in all sub shapes with a type (Method for TUI or GUI)
2191 //================================================================================
2193 GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapeAll(GEOM::GEOM_Shape_ptr shape,
2194 CORBA::Short ShapeType)
2195 throw (SALOME::SALOME_Exception)
2197 return SubShapesAll(shape, (TopAbs_ShapeEnum) ShapeType);
2200 //================================================================================
2201 // function : SubShapeAllSorted()
2202 // purpose : Explode a shape in all sub shapes with a type (Method for TUI or GUI)
2203 //================================================================================
2205 GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapeAllSorted(GEOM::GEOM_Shape_ptr shape,
2206 CORBA::Short ShapeType)
2207 throw (SALOME::SALOME_Exception)
2209 return SubShapesAll(shape, (TopAbs_ShapeEnum) ShapeType, Standard_True);
2212 //================================================================================
2213 // function : SubShapeAllSorted()
2215 //================================================================================
2217 GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapesAll(GEOM::GEOM_Shape_ptr shape,
2218 const TopAbs_ShapeEnum ShapeType,
2219 const Standard_Boolean Sort)
2220 throw (SALOME::SALOME_Exception)
2222 /* List of sub shapes returned */
2223 GEOM::GEOM_Gen::ListOfGeomShapes_var listOfGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
2224 listOfGeomShapes->length(0) ;
2226 TopoDS_Shape mainTopo = GetTopoShape(shape);
2227 TopoDS_Shape mainShape;
2230 if ( shape->IsMainShape() ) {
2231 mainShape = GetTopoShape(shape);
2234 shape = GetIORFromString( shape->MainName() );
2237 if( mainTopo.IsNull() ) {
2238 THROW_SALOME_CORBA_EXCEPTION("In GEOM_Gen_i::SubShapeAll() : null main shape",
2242 /* List/index : field set for any sub shape */
2243 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
2244 ListOfID->length(1) ;
2246 // retrieve all subshapes
2247 TopTools_MapOfShape mapShape;
2248 TopTools_ListOfShape listShape;
2250 if (mainTopo.ShapeType()==TopAbs_COMPOUND && ShapeType==TopAbs_SHAPE)
2252 TopoDS_Iterator It(mainTopo,Standard_True,Standard_True );
2253 for ( ; It.More(); It.Next() )
2254 if (mapShape.Add( It.Value() ))
2255 listShape.Append( It.Value() );
2259 TopExp_Explorer exp ( mainTopo, ShapeType);
2260 for ( ; exp.More(); exp.Next() )
2261 if (mapShape.Add( exp.Current() ))
2262 listShape.Append( exp.Current() );
2266 SortShapes(listShape);
2268 /* Create all sub shapes */
2270 GEOM::GEOM_Shape_var result;
2272 TopTools_ListIteratorOfListOfShape itSub (listShape);
2273 for (index = 1; itSub.More(); itSub.Next(), ++index)
2275 const TopoDS_Shape& SubShape = itSub.Value();
2276 // check if SubShape is already in OCAFDS and ...
2277 if ( TNaming_Tool::HasLabel( myCurrentOCAFDoc->Main(), SubShape ) )
2280 TDF_Label Lab = TNaming_Tool::Label( myCurrentOCAFDoc->Main(), SubShape, TransDef );
2281 Handle(TDataStd_Name) Att;
2282 if ( Lab.FindAttribute( TDataStd_Name::GetID(), Att ) )
2284 TCollection_AsciiString nameIOR( Att->Get() );
2285 result = GEOM::GEOM_Shape::_narrow(_orb->string_to_object( nameIOR.ToCString() ));
2286 // ... it is subshape of <shape>
2287 if ( strcmp( result->MainName(), _orb->object_to_string(shape) ) == 0 )
2289 listOfGeomShapes->length(index) ;
2290 listOfGeomShapes[index-1] = result ;
2297 // ListOfID[0] = index;
2299 ListOfID[0] = GetIndexTopology( SubShape, mainShape ) ;
2300 result = CreateSubObject( SubShape, shape, ListOfID);
2301 /* Add each sub shape in the list returned */
2302 listOfGeomShapes->length(index) ;
2303 listOfGeomShapes[index-1] = result ;
2306 return listOfGeomShapes._retn() ;
2310 //=================================================================================
2311 // function : MakeBoolean()
2312 // purpose : Boolean operation according to the type 'operation'
2313 //=================================================================================
2314 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeBoolean(GEOM::GEOM_Shape_ptr shape1,
2315 GEOM::GEOM_Shape_ptr shape2,
2316 CORBA::Long operation)
2317 throw (SALOME::SALOME_Exception)
2319 GEOM::GEOM_Shape_var result;
2320 TopoDS_Shape shape ;
2321 TopoDS_Shape aShape1 ;
2322 TopoDS_Shape aShape2 ;
2325 aShape1 = GetTopoShape(shape1) ;
2326 aShape2 = GetTopoShape(shape2) ;
2328 if( aShape1.IsNull() || aShape2.IsNull() ) {
2329 THROW_SALOME_CORBA_EXCEPTION("Boolean aborted : argument shape is null", SALOME::BAD_PARAM);
2334 case 1 : /* Common */
2335 shape = BRepAlgoAPI_Common(aShape1, aShape2).Shape();
2338 shape = BRepAlgoAPI_Cut(aShape1, aShape2).Shape();
2341 shape = BRepAlgoAPI_Fuse(aShape1, aShape2).Shape();
2343 case 4 : /* Section */
2344 shape = BRepAlgoAPI_Section(aShape1, aShape2).Shape();
2347 MESSAGE("Boolean operation not known : " << operation ) ;
2351 catch(Standard_Failure) {
2352 THROW_SALOME_CORBA_EXCEPTION("Exception catched in boolean operation", SALOME::BAD_PARAM);
2355 /* We test the validity of resulting shape */
2356 if( !BRepAlgoAPI::IsValid(shape) ) {
2357 THROW_SALOME_CORBA_EXCEPTION("Boolean aborted : non valid shape result", SALOME::BAD_PARAM);
2360 result = CreateObject(shape) ;
2362 /* put shape and name into geom/OCAF doc */
2363 GEOMDS_Commands GC(myCurrentOCAFDoc->Main());
2364 /* add attributs 'shape' and' name_io'r in a new label */
2365 TDF_Label Lab = GC.Generated(aShape1, shape, result->Name() );
2366 TCollection_AsciiString entry;
2367 TDF_Tool::Entry(Lab, entry);
2368 result->ShapeId( entry.ToCString() ) ;
2370 /* Create a new label */
2371 TDF_Label NewLab = Lab.NewChild();
2372 TCollection_ExtendedString Value("Arguments");
2373 TDataStd_Name::Set(NewLab,Value);
2375 TDF_Label NewLab1 = NewLab.NewChild();
2377 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), shape1->ShapeId(), RefLab);
2378 TDF_Reference::Set(NewLab1, RefLab);
2380 TDF_Label NewLab2 = NewLab.NewChild();
2381 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), shape2->ShapeId(), RefLab);
2382 TDF_Reference::Set(NewLab2, RefLab);
2387 //=================================================================================
2388 // function : MakeFuse()
2389 // purpose : Special purpose !
2390 //=================================================================================
2391 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFuse(GEOM::GEOM_Shape_ptr shape1,
2392 GEOM::GEOM_Shape_ptr shape2)
2393 throw (SALOME::SALOME_Exception)
2395 GEOM::GEOM_Shape_var result;
2396 TopoDS_Shape aShape1 = GetTopoShape(shape1) ;
2397 TopoDS_Shape aShape2 = GetTopoShape(shape2) ;
2398 if( aShape1.IsNull() || aShape2.IsNull() ) {
2399 THROW_SALOME_CORBA_EXCEPTION("Fuse aborted : shape in argument is null", SALOME::BAD_PARAM);
2403 shape = BRepAlgoAPI_Fuse(aShape1, aShape2).Shape();
2405 catch(Standard_Failure) {
2406 THROW_SALOME_CORBA_EXCEPTION("Exception catched in Fuse operation", SALOME::BAD_PARAM);
2409 /* We test the validity of resulting shape */
2410 if( !BRepAlgoAPI::IsValid(shape) ) {
2411 THROW_SALOME_CORBA_EXCEPTION("Fuse aborted : non valid shape result", SALOME::BAD_PARAM);
2414 result = CreateObject(shape) ;
2416 /* put shape and name into geom/OCAF doc */
2417 GEOMDS_Commands GC(myCurrentOCAFDoc->Main());
2418 /* add attributs 'shape' and' name_io'r in a new label */
2419 TDF_Label Lab = GC.Generated(aShape1, shape, result->Name() );
2420 TCollection_AsciiString entry;
2421 TDF_Tool::Entry(Lab, entry);
2422 result->ShapeId( entry.ToCString() ) ;
2424 /* Create a new label */
2425 TDF_Label NewLab = Lab.NewChild();
2426 TCollection_ExtendedString Value("Arguments");
2427 TDataStd_Name::Set(NewLab,Value);
2429 TDF_Label NewLab1 = NewLab.NewChild();
2431 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), shape1->ShapeId(), RefLab);
2432 TDF_Reference::Set(NewLab1, RefLab);
2434 TDF_Label NewLab2 = NewLab.NewChild();
2435 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), shape2->ShapeId(), RefLab);
2436 TDF_Reference::Set(NewLab2, RefLab);
2441 //================================================================================
2442 // function : MakeAxisStruct()
2443 // purpose : Create a structure GEOM::AxisStruct (see IDL file)
2444 //================================================================================
2445 GEOM::AxisStruct GEOM_Gen_i::MakeAxisStruct(CORBA::Double x,
2452 GEOM::AxisStruct A ;
2453 A.x = x ; A.y = y ; A.z = z ;
2454 A.vx = vx ; A.vy = vy ; A.vz = vz ;
2459 //================================================================================
2460 // function : MakePointStruct()
2461 // purpose : Create a structure GEOM::PointStruct (see IDL file)
2462 //================================================================================
2463 GEOM::PointStruct GEOM_Gen_i::MakePointStruct(CORBA::Double x,
2467 beginService( "GEOM_Gen_i::MakePointStruct" );
2468 GEOM::PointStruct p ;
2469 p.x = x ; p.y = y ; p.z = z ;
2470 endService( "GEOM_Gen_i::MakePointStruct" );
2474 //================================================================================
2475 // function : MakeDirection()
2476 // purpose : Create a structure GEOM::DirStruct (see IDL file)
2477 //================================================================================
2478 GEOM::DirStruct GEOM_Gen_i::MakeDirection(const GEOM::PointStruct& p)
2481 d.PS.x = p.x ; d.PS.y = p.y ; d.PS.z = p.z ;
2485 //=================================================================================
2486 // function : MakeBox()
2487 // purpose : Create a box topology.
2488 //=================================================================================
2489 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeBox(CORBA::Double x1,
2495 throw (SALOME::SALOME_Exception)
2497 gp_Pnt P1(x1,y1,z1);
2498 gp_Pnt P2(x2,y2,z2);
2499 GEOM::GEOM_Shape_var result ;
2502 tds = BRepPrimAPI_MakeBox(P1,P2).Shape();
2504 catch(Standard_Failure) {
2505 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeBox", SALOME::BAD_PARAM);
2509 THROW_SALOME_CORBA_EXCEPTION("Make Box aborted : null shape", SALOME::BAD_PARAM);
2512 result = CreateObject(tds);
2513 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2514 result->ShapeId(entry) ;
2519 //================================================================================
2520 // function : MakeCylinder
2521 // purpose : Create a cylinder topology
2522 //================================================================================
2523 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCylinder(const GEOM::PointStruct& pstruct,
2524 const GEOM::DirStruct& dstruct,
2525 CORBA::Double radius,
2526 CORBA::Double height)
2527 throw (SALOME::SALOME_Exception)
2529 GEOM::GEOM_Shape_var result;
2531 gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ;
2532 gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
2536 tds = BRepPrimAPI_MakeCylinder(axis, radius, height).Shape();
2538 catch(Standard_Failure) {
2539 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeCylinder", SALOME::BAD_PARAM);
2543 THROW_SALOME_CORBA_EXCEPTION("Make Cylinder aborted", SALOME::BAD_PARAM);
2545 result = CreateObject(tds);
2546 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2547 result->ShapeId(entry);
2553 //================================================================================
2554 // function : MakeSphere()
2555 // purpose : Make a sphere topology
2556 //================================================================================
2557 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSphere(CORBA::Double x1,
2560 CORBA::Double radius)
2561 throw (SALOME::SALOME_Exception)
2563 GEOM::GEOM_Shape_var result ;
2566 tds = BRepPrimAPI_MakeSphere(gp_Pnt(x1,y1,z1), radius).Shape();
2568 catch(Standard_Failure) {
2569 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeSphere", SALOME::BAD_PARAM);
2573 THROW_SALOME_CORBA_EXCEPTION("Make Sphere aborted", SALOME::BAD_PARAM);
2575 result = CreateObject(tds) ;
2576 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2577 result->ShapeId(entry);
2583 //================================================================================
2584 // function : MakeTorus()
2585 // purpose : Create a torus topology
2586 //================================================================================
2587 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeTorus( const GEOM::PointStruct& pstruct,
2588 const GEOM::DirStruct& dstruct,
2589 CORBA::Double major_radius,
2590 CORBA::Double minor_radius )
2591 throw (SALOME::SALOME_Exception)
2593 GEOM::GEOM_Shape_var result;
2595 gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ;
2596 gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
2600 tds = BRepPrimAPI_MakeTorus(axis, major_radius, minor_radius).Shape();
2602 catch(Standard_Failure) {
2603 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeTorus", SALOME::BAD_PARAM);
2607 THROW_SALOME_CORBA_EXCEPTION("Make torus aborted", SALOME::BAD_PARAM);
2609 result = CreateObject(tds);
2610 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2611 result->ShapeId(entry);
2616 //================================================================================
2617 // function : MakeCone()
2618 // purpose : Create a cone topology
2619 //================================================================================
2620 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCone(const GEOM::PointStruct& pstruct,
2621 const GEOM::DirStruct& dstruct,
2622 CORBA::Double radius1,
2623 CORBA::Double radius2,
2624 CORBA::Double height)
2625 throw (SALOME::SALOME_Exception)
2627 GEOM::GEOM_Shape_var result;
2629 gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ;
2630 gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
2634 /* Cone doesn't work if same radius */
2635 if( fabs(radius1-radius2) <= Precision::Confusion() ) {
2636 tds = BRepPrimAPI_MakeCylinder(axis, (radius1+radius2)/2.0, height).Shape();
2639 tds = BRepPrimAPI_MakeCone(axis, radius1, radius2, height).Shape();
2642 catch(Standard_Failure) {
2643 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeCone", SALOME::BAD_PARAM);
2647 THROW_SALOME_CORBA_EXCEPTION("Make Cone aborted", SALOME::BAD_PARAM);
2649 result = CreateObject(tds);
2650 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2651 result->ShapeId(entry);
2657 //==================================================================================
2658 // function : ImportIGES()
2659 // purpose : Import shape from an IGES (IGS) file
2660 // : LPN modified 7 mai 2002
2661 //==================================================================================
2662 GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportIGES(const char* filename)
2663 throw (SALOME::SALOME_Exception)
2665 GEOM::GEOM_Shape_var result ;
2666 //VRV: OCC 4.0 migration
2667 IGESControl_Reader aReader;
2668 //VRV: OCC 4.0 migration
2670 IFSelect_ReturnStatus stat = aReader.ReadFile((char*)filename);
2671 if ( stat != IFSelect_RetDone ) {
2672 THROW_SALOME_CORBA_EXCEPTION("Error in reading import file", SALOME::BAD_PARAM); }
2674 MESSAGE("ImportIGES : all Geometry Transfer" << endl ) ;
2676 aReader.TransferRoots(false);
2678 MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes() << endl );
2679 TopoDS_Shape shape = aReader.OneShape();
2681 if ( !shape.IsNull() ) {
2682 /* Final CORBA object creation */
2683 result = CreateObject(shape) ;
2684 const char *entry = InsertInLabel( shape, result->Name(), myCurrentOCAFDoc ) ;
2685 result->ShapeId(entry);
2689 catch(Standard_Failure) {
2690 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportIGES()", SALOME::BAD_PARAM);
2693 THROW_SALOME_CORBA_EXCEPTION("Import IGES aborted : internal error", SALOME::BAD_PARAM);
2698 //==================================================================================
2699 // function : ImportSTEP()
2700 // purpose : Import shape from an STEP (stp) file
2701 // : 'result' is a compound of shapes if file contains more entities.
2702 //==================================================================================
2703 GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportSTEP(const char* filename)
2704 throw (SALOME::SALOME_Exception)
2706 GEOM::GEOM_Shape_var result ;
2707 //VRV: OCC 4.0 migration
2708 STEPControl_Reader aReader;
2709 //VRV: OCC 4.0 migration
2711 TopoDS_Compound compound;
2713 B.MakeCompound( compound );
2716 IFSelect_ReturnStatus status = aReader.ReadFile((char*)filename);
2718 if (status == IFSelect_RetDone) {
2719 Standard_Boolean failsonly = Standard_False ;
2720 aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
2721 /* Root transfers */
2722 Standard_Integer nbr = aReader.NbRootsForTransfer();
2723 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
2725 for ( Standard_Integer n=1; n <= nbr; n++) {
2727 Standard_Boolean ok = aReader.TransferRoot(n);
2728 /* Collecting resulting entities */
2729 Standard_Integer nbs = aReader.NbShapes();
2731 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
2733 for ( Standard_Integer i=1; i<=nbs; i++ ) {
2734 TopoDS_Shape aShape = aReader.Shape(i);
2735 if ( aShape.IsNull() )
2736 THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
2738 /* For a single entity */
2739 if(nbr == 1 && nbs == 1) {
2740 result = CreateObject(aShape) ;
2741 const char *entry = InsertInLabel(aShape, result->Name(), myCurrentOCAFDoc) ;
2742 result->ShapeId(entry);
2746 B.Add( compound, aShape ) ;
2751 TopoDS_Shape tds = compound ;
2752 result = CreateObject(tds) ;
2753 if( CORBA::is_nil(result) )
2754 THROW_SALOME_CORBA_EXCEPTION("Translation aborted : null result", SALOME::BAD_PARAM);
2755 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
2756 result->ShapeId(entry);
2761 catch(Standard_Failure) {
2762 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
2768 //==================================================================================
2769 // function : Partition()
2771 //==================================================================================
2773 GEOM::GEOM_Shape_ptr
2774 GEOM_Gen_i::Partition(const GEOM::GEOM_Gen::ListOfIOR& ListShapes,
2775 const GEOM::GEOM_Gen::ListOfIOR& ListTools,
2776 const GEOM::GEOM_Gen::ListOfIOR& ListKeepInside,
2777 const GEOM::GEOM_Gen::ListOfIOR& ListRemoveInside,
2778 const CORBA::Short Limit)
2779 throw (SALOME::SALOME_Exception)
2781 GEOM::GEOM_Shape_var aResult;
2783 //MESSAGE ("In Partition");
2786 unsigned int ind, nbshapes = 0;
2787 nbshapes += ListShapes.length() + ListTools.length();
2788 nbshapes += ListKeepInside.length() + ListRemoveInside.length();
2790 Partition_Spliter PS;
2791 TopTools_MapOfShape ShapesMap(nbshapes), ToolsMap(nbshapes);
2793 // add object shapes that are in ListShapes;
2794 for ( ind = 0; ind < ListShapes.length(); ind++) {
2796 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[ind] );
2797 TopoDS_Shape Shape = GetTopoShape(aShape);
2798 if(Shape.IsNull() ) {
2799 //MESSAGE ( "In Partition a shape is null" );
2800 THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM);
2802 if ( ShapesMap.Add( Shape ))
2806 // add tool shapes that are in ListTools and not in ListShapes;
2807 for (ind = 0; ind < ListTools.length(); ind++) {
2809 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListTools[ind] );
2810 TopoDS_Shape Shape = GetTopoShape(aShape);
2811 if(Shape.IsNull() ) {
2812 //MESSAGE ( "In Partition a tool shape is null" );
2813 THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM);
2815 if ( !ShapesMap.Contains( Shape ) && ToolsMap.Add( Shape ))
2819 // add shapes that are in ListKeepInside, as object shapes;
2820 for (ind = 0; ind < ListKeepInside.length(); ind++) {
2822 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListKeepInside[ind] );
2823 TopoDS_Shape Shape = GetTopoShape(aShape);
2824 if(Shape.IsNull() ) {
2825 //MESSAGE ( "In Partition a Keep Inside shape is null" );
2826 THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM);
2828 if (!ToolsMap.Contains( Shape ) &&
2829 ShapesMap.Add( Shape ))
2833 // add shapes that are in ListRemoveInside, as object shapes;
2834 for (ind = 0; ind < ListRemoveInside.length(); ind++) {
2836 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListRemoveInside[ind] );
2837 TopoDS_Shape Shape = GetTopoShape(aShape);
2838 if(Shape.IsNull() ) {
2839 //MESSAGE ( "In Partition a Remove Inside shape is null" );
2840 THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM);
2842 if (!ToolsMap.Contains( Shape ) &&
2843 ShapesMap.Add( Shape ) )
2847 PS.Compute ((TopAbs_ShapeEnum) Limit);
2849 // suppress result outside of shapes in KInsideMap
2850 for (ind = 0; ind < ListKeepInside.length(); ind++) {
2851 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListKeepInside[ind] );
2852 TopoDS_Shape Shape = GetTopoShape(aShape);
2853 PS.KeepShapesInside( Shape );
2856 // suppress result inside of shapes in RInsideMap
2857 for (ind = 0; ind < ListRemoveInside.length(); ind++) {
2859 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListRemoveInside[ind] );
2860 TopoDS_Shape Shape = GetTopoShape(aShape);
2861 PS.RemoveShapesInside( Shape );
2866 if( !BRepAlgoAPI::IsValid(tds) ) {
2867 //MESSAGE ( "In Partition: non valid shape result" );
2868 THROW_SALOME_CORBA_EXCEPTION("Partition aborted : non valid shape result", SALOME::BAD_PARAM);
2871 catch (Standard_Failure) {
2872 //MESSAGE ( "In Partition: Exception catched in GEOM_Gen_i::Partition()" );
2873 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::Partition", SALOME::BAD_PARAM);
2876 aResult = CreateObject(tds) ;
2878 /* add attributs S and mystr in a new label */
2879 GEOMDS_Commands GC(myCurrentOCAFDoc->Main());
2880 TDF_Label Lab = GC.AddShape(tds, aResult->Name() );
2881 TCollection_AsciiString entry;
2882 TDF_Tool::Entry(Lab,entry);
2883 aResult->ShapeId( entry.ToCString() ) ;
2887 /* Create a new label */
2888 TDF_Label NewLab = Lab.NewChild();
2889 TCollection_ExtendedString Value("Arguments");
2890 TDataStd_Name::Set(NewLab,Value);
2893 for (unsigned int ind = 0; ind < ListShapes.length(); ind++) {
2894 TDF_Label NewLab1 = NewLab.NewChild();
2896 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[ind] );
2897 Standard_CString anEntry = aShape->ShapeId();
2899 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), anEntry, RefLab);
2900 TDF_Reference::Set(NewLab1,RefLab);
2903 for (unsigned int ind = 0; ind < ListTools.length(); ind++) {
2904 TDF_Label NewLab1 = NewLab.NewChild();
2906 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListTools[ind] );
2907 Standard_CString anEntry = aShape->ShapeId();
2909 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), anEntry, RefLab);
2910 TDF_Reference::Set(NewLab1,RefLab);
2913 for (unsigned int ind = 0; ind < ListKeepInside.length(); ind++) {
2914 TDF_Label NewLab1 = NewLab.NewChild();
2916 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListKeepInside[ind] );
2917 Standard_CString anEntry = aShape->ShapeId();
2919 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), anEntry, RefLab);
2920 TDF_Reference::Set(NewLab1,RefLab);
2923 for (unsigned int ind = 0; ind < ListRemoveInside.length(); ind++) {
2924 TDF_Label NewLab1 = NewLab.NewChild();
2926 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListRemoveInside[ind] );
2927 Standard_CString anEntry = aShape->ShapeId();
2929 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), anEntry, RefLab);
2930 TDF_Reference::Set(NewLab1,RefLab);
2938 //==================================================================================
2939 // function : MakeFilling()
2940 // purpose : Create a surface from section curves filling
2941 //==================================================================================
2942 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFilling(GEOM::GEOM_Shape_ptr myShape,
2943 CORBA::Short mindeg,
2944 CORBA::Short maxdeg,
2945 CORBA::Double tol3d,
2946 CORBA::Double tol2d,
2947 CORBA::Short nbiter)
2948 throw (SALOME::SALOME_Exception)
2950 GEOM::GEOM_Shape_var result ;
2952 TopoDS_Shape aShape = GetTopoShape(myShape) ;
2953 if( aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND ) {
2954 THROW_SALOME_CORBA_EXCEPTION("MakeFilling aborted : null shape or not a compound", SALOME::BAD_PARAM);
2958 /* we verify the contents of the shape */
2959 TopExp_Explorer Ex ;
2960 TopoDS_Shape Scurrent ;
2961 Standard_Real First, Last ;
2962 Handle(Geom_Curve) C ;
2963 GeomFill_SectionGenerator Section ;
2965 Standard_Integer i = 0 ;
2966 for(Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
2967 Scurrent = Ex.Current() ;
2968 if( Scurrent.IsNull() || Scurrent.ShapeType() != TopAbs_EDGE) {
2969 THROW_SALOME_CORBA_EXCEPTION("Initial shape doesn't contain only edges !", SALOME::BAD_PARAM);
2971 C = BRep_Tool::Curve(TopoDS::Edge(Scurrent), First, Last);
2972 C = new Geom_TrimmedCurve(C, First, Last);
2973 Section.AddCurve(C) ;
2977 /* a 'tolerance' is used to compare 2 knots : see GeomFill_Generator.cdl */
2978 /* We set 'tolerance' = tol3d */
2979 // Section.Perform( tol3d ) ; NRI */
2980 Section.Perform( Precision::Confusion() ) ;
2981 Handle(GeomFill_Line) Line = new GeomFill_Line(i) ;
2983 GeomFill_AppSurf App(mindeg, maxdeg, tol3d, tol2d, nbiter) ; /* user parameters */
2984 App.Perform(Line, Section) ;
2986 if (!App.IsDone()) {
2987 THROW_SALOME_CORBA_EXCEPTION("Filling aborted : non valid shape result", SALOME::BAD_PARAM);
2989 Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
2990 App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
2991 Handle(Geom_BSplineSurface) GBS = new Geom_BSplineSurface(App.SurfPoles(),
3000 if( GBS.IsNull() ) {
3001 THROW_SALOME_CORBA_EXCEPTION("Make Filling aborted", SALOME::BAD_PARAM);
3003 tds = BRepBuilderAPI_MakeFace(GBS) ;
3005 catch(Standard_Failure) {
3006 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeFilling", SALOME::BAD_PARAM);
3009 /* We test the validity of resulting shape */
3010 if( !BRepAlgoAPI::IsValid(tds) ) {
3011 THROW_SALOME_CORBA_EXCEPTION("Filling aborted : non valid shape result", SALOME::BAD_PARAM);
3014 result = CreateObject(tds) ;
3015 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3022 //=================================================================================
3023 // function : MakeGlueFaces()
3025 //=================================================================================
3027 TopoDS_Face GEOM_Gen_i::FindSameFace(const TopoDS_Shape& aShape,
3028 const TopoDS_Face& F,
3032 bool isSame = false;
3033 for (TopExp_Explorer exf(aShape,TopAbs_FACE); exf.More(); exf.Next())
3035 //MESSAGE("--- test a face");
3037 aFace = TopoDS::Face(exf.Current());
3038 TopTools_ListOfShape liste1;
3039 TopTools_ListOfShape liste2;
3040 for (TopExp_Explorer exp(aFace,TopAbs_VERTEX); exp.More(); exp.Next())
3042 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
3045 for (TopExp_Explorer exp(F,TopAbs_VERTEX); exp.More(); exp.Next())
3047 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
3051 if (liste1.Extent() == liste2.Extent())
3053 TopTools_ListIteratorOfListOfShape it1(liste1);
3055 for (; it1.More(); it1.Next())
3057 bool foundSamePoint = false;
3058 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(it1.Value()));
3059 TopTools_ListIteratorOfListOfShape it2(liste2);
3060 for (it2; it2.More(); it2.Next())
3062 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(it2.Value()));
3063 double d = P1.Distance(P2);
3067 //MESSAGE(" found Same Point : "<<nbFound<<" - "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z());
3068 foundSamePoint = true;
3072 isSame = isSame && foundSamePoint;
3073 if (! isSame) break; // a vertex does not correspond : not same face
3078 //MESSAGE(" --- Found Same Face");
3079 break; // a face corresponding to F is found
3082 if (! isSame) aFace.Nullify(); // return null face
3086 TopoDS_Edge GEOM_Gen_i::FindSameEdge(const TopoDS_Face& nf,
3090 TopoDS_Face newFace = TopoDS::Face(nf.Oriented(TopAbs_REVERSED));
3091 TopoDS_Vertex VFirst, VLast;
3092 TopExp::Vertices(Eold, VFirst, VLast);
3093 gp_Pnt Pf = BRep_Tool::Pnt(VFirst);
3094 gp_Pnt Pl = BRep_Tool::Pnt(VLast);
3096 for (TopExp_Explorer ee(newFace,TopAbs_EDGE); ee.More(); ee.Next())
3098 const TopoDS_Edge& E = TopoDS::Edge(ee.Current());
3099 TopoDS_Vertex VFn, VLn;
3100 TopExp::Vertices(E, VFn, VLn);
3101 gp_Pnt Pfn = BRep_Tool::Pnt(VFn);
3102 gp_Pnt Pln = BRep_Tool::Pnt(VLn);
3103 double dff = Pf.Distance(Pfn);
3104 double dfl = Pf.Distance(Pln);
3105 double dlf = Pl.Distance(Pfn);
3106 double dll = Pl.Distance(Pln);
3107 if ((dff < tol3d) && (dll <tol3d))
3109 //MESSAGE("--- edge forward " <<Pf.X()<<" "<<Pf.Y()<<" "<<Pf.Z()<<" "<<Pl.X()<<" "<<Pl.Y()<<" "<<Pl.Z());
3110 Enew = TopoDS::Edge(E.Oriented(TopAbs_FORWARD));
3111 Eold = TopoDS::Edge(Eold.Oriented(TopAbs_FORWARD));
3114 if ((dfl < tol3d) && (dlf <tol3d))
3116 //MESSAGE("--- edge reversed " <<Pf.X()<<" "<<Pf.Y()<<" "<<Pf.Z()<<" "<<Pl.X()<<" "<<Pl.Y()<<" "<<Pl.Z());
3117 Enew = TopoDS::Edge(E.Oriented(TopAbs_REVERSED));
3118 Eold = TopoDS::Edge(Eold.Oriented(TopAbs_FORWARD));
3125 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeGlueFaces(GEOM::GEOM_Shape_ptr myShape,
3127 throw (SALOME::SALOME_Exception)
3130 // prendre un premier shell dans la liste des shells
3131 // initialiser un compshell avec ce shell
3132 // tant qu'il reste des shells dans la liste
3133 // chercher un shell qui a des faces en commun avec le compshell
3134 // creer un BRepTools_Quilt
3135 // recenser les faces communes issues du compshell, les ajouter au quilt
3136 // recenser les faces restantes du shell a inclure, les ajouter au quilt
3137 // recenser les edges en double, a remplacer
3138 // pour chaque paire d'edge
3139 // tester l'orientation relative des aretes
3140 // bind dans le quilt de Eold.Forward et Enew.Forward (ou reverse)
3141 // recuperer le nouveau shell
3142 // l'incorporer dans le compshell
3143 // appliquer BRepTools_SameParameter au compshell
3144 // (rendre parametres 2D des edges identiques aux parametres 3D)
3146 GEOM::GEOM_Shape_var result ;
3148 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3151 bu.MakeCompound(C); // empty compound;
3152 TopTools_ListOfShape shellList;
3153 for (TopExp_Explorer exp(aShape,TopAbs_SHELL); exp.More(); exp.Next())
3155 const TopoDS_Shell& S = TopoDS::Shell(exp.Current());
3156 shellList.Append(S);
3158 TopTools_ListIteratorOfListOfShape its(shellList);
3161 THROW_SALOME_CORBA_EXCEPTION("glue aborted : no shell in shape", SALOME::BAD_PARAM);
3163 TopoDS_Shell S = TopoDS::Shell(its.Value());
3164 bu.Add(C, S); // add first shell to compound
3165 shellList.Remove(its);
3166 its.Initialize(shellList);
3167 bool shellAdded = true;
3168 while ((shellList.Extent() > 0) && shellAdded)
3170 //MESSAGE("more shells : "<< shellList.Extent());
3172 its.Initialize(shellList);
3173 for(; its.More(); its.Next())
3175 //MESSAGE("one more shell to try");
3176 TopTools_ListOfShape newFaces; // common faces from new compound
3177 TopTools_ListOfShape oldFaces; // common faces from shell to add
3178 TopTools_ListOfShape addFaces; // not common faces from shell to add
3179 TopTools_ListOfShape newEdges; // common edges from new compound
3180 TopTools_ListOfShape oldEdges; // common edges from face to add
3181 TopoDS_Compound CFN;
3182 TopoDS_Compound CFO;
3183 bu.MakeCompound(CFN); // empty compound for new faces
3184 bu.MakeCompound(CFO); // empty compound for old faces
3185 S = TopoDS::Shell(its.Value());
3186 for (TopExp_Explorer exp(S,TopAbs_FACE); exp.More(); exp.Next())
3188 //MESSAGE("--- try to find corresponding face in new compound");
3189 TopoDS_Face F = TopoDS::Face(exp.Current());
3190 TopoDS_Face newFace = FindSameFace(C,F,tol3d);
3191 if (! newFace.IsNull())
3193 //MESSAGE("--- face found");
3194 newFaces.Append(newFace);
3195 bu.Add(CFN, newFace); // common faces from new compound
3197 for (TopExp_Explorer ee(F,TopAbs_EDGE);ee.More();ee.Next())
3199 //MESSAGE("--- find edge pair");
3200 TopoDS_Edge Eold = TopoDS::Edge(ee.Current());
3201 const TopoDS_Edge& Enew = FindSameEdge(newFace, Eold, tol3d);
3202 oldEdges.Append(Eold);
3203 newEdges.Append(Enew);
3210 bu.Add(CFO, F); // not common faces from shell to add
3213 if ( !newFaces.IsEmpty())
3215 //MESSAGE("--- some faces found ---");
3217 BRepTools_Quilt glue;
3219 TopTools_ListIteratorOfListOfShape ito(oldEdges);
3220 TopTools_ListIteratorOfListOfShape itn(newEdges);
3221 for (; ito.More(); ito.Next())
3223 //MESSAGE("--- bind");
3224 glue.Bind(TopoDS::Edge(ito.Value()), TopoDS::Edge(itn.Value()));
3228 TopoDS_Compound newc = TopoDS::Compound(glue.Shells());
3229 for (TopExp_Explorer exs(newc,TopAbs_SHELL); exs.More(); exs.Next())
3231 TopoDS_Shell NS = TopoDS::Shell(exs.Current());
3234 shellList.Remove(its);
3235 //MESSAGE("--- remove shell from list");
3240 //MESSAGE("---" << shellList.Extent() << " " << shellAdded);
3242 TopExp_Explorer exp(C,TopAbs_SHELL);
3243 Standard_Integer ish=0;
3244 TopoDS_Compound Res;
3247 B.MakeCompound(Res);
3248 TopoDS_Shape theShape;
3250 for (; exp.More(); exp.Next())
3252 TopoDS_Shape Sh = exp.Current();
3255 BRepClass3d_SolidClassifier SC(Sol);
3256 SC.PerformInfinitePoint(1.E-6); // cf. BRepFill_Confusion() - BRepFill_Evolved.cxx
3257 if (SC.State() == TopAbs_IN)
3260 B.Add(Sol,Sh.Reversed());
3265 if (ish == 1) { theShape = Sol;}
3266 else { theShape = Res;}
3268 BRepLib::SameParameter(theShape, 1.E-5, Standard_True);
3270 result = CreateObject(tds);
3271 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3276 //=================================================================================
3277 // function : MakeSewing()
3279 //=================================================================================
3280 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewing( const GEOM::GEOM_Gen::ListOfIOR& ListShapes,
3281 CORBA::Double precision )
3282 throw (SALOME::SALOME_Exception)
3284 GEOM::GEOM_Shape_var result ;
3286 BRepOffsetAPI_Sewing aMethod ;
3289 /* default OCC is 1.0e-06 */
3290 aMethod.Init(precision, Standard_False);
3291 for ( unsigned int i = 0; i < ListShapes.length(); i++) {
3292 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[i] );
3293 TopoDS_Shape Shape = GetTopoShape(aShape) ;
3294 if( Shape.IsNull() ) {
3295 THROW_SALOME_CORBA_EXCEPTION("MakeSewing aborted : null shape during operation", SALOME::BAD_PARAM);
3297 aMethod.Add(Shape) ;
3301 tds = aMethod.SewedShape() ;
3302 if( !BRepAlgoAPI::IsValid(tds) ) {
3303 THROW_SALOME_CORBA_EXCEPTION("Make Sewing aborted : non valid shape", SALOME::BAD_PARAM);
3305 if( tds.IsNull() ) {
3306 THROW_SALOME_CORBA_EXCEPTION("Make Sewing aborted : null shape", SALOME::BAD_PARAM);
3309 catch (Standard_Failure) {
3310 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeSewing", SALOME::BAD_PARAM);
3313 result = CreateObject(tds);
3314 InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
3318 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewingShape( GEOM::GEOM_Shape_ptr aShape,
3319 CORBA::Double precision )
3320 throw (SALOME::SALOME_Exception)
3322 GEOM::GEOM_Shape_var result ;
3323 TopoDS_Shape tds, S ;
3324 BRepOffsetAPI_Sewing aMethod ;
3327 S = GetTopoShape(aShape) ;
3329 THROW_SALOME_CORBA_EXCEPTION("In Sewing a Shape is null", SALOME::BAD_PARAM);
3332 /* default OCC is 1.0e-06 */
3333 aMethod.Init(precision, Standard_False);
3334 for ( TopExp_Explorer exp( S, TopAbs_FACE); exp.More(); exp.Next() ) {
3335 const TopoDS_Face& F = TopoDS::Face(exp.Current());
3340 tds = aMethod.SewedShape() ;
3341 if( !BRepAlgoAPI::IsValid(tds) ) {
3342 THROW_SALOME_CORBA_EXCEPTION("Make Sewing aborted : non valid shape", SALOME::BAD_PARAM);
3345 catch (Standard_Failure) {
3346 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeSewing", SALOME::BAD_PARAM);
3349 result = CreateObject(tds);
3350 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3351 result->ShapeId(entry) ;
3355 //==================================================================================
3356 // function : OrientationChange()
3357 // purpose : Change the orientation of a new shape
3358 // : TopAbs_FORWARD < -- > TopAbs_REVERSED
3360 // : WARNING : for the moment we make a new shape !
3361 //==================================================================================
3362 GEOM::GEOM_Shape_ptr GEOM_Gen_i::OrientationChange(GEOM::GEOM_Shape_ptr aShape)
3363 throw (SALOME::SALOME_Exception)
3365 GEOM::GEOM_Shape_var result ;
3366 BRep_Builder aBuilder;
3368 TopoDS_Shape shape = GetTopoShape(aShape) ;
3369 if( shape.IsNull() ) {
3370 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
3373 BRepBuilderAPI_Copy Copy(shape);
3374 if( Copy.IsDone() ) {
3375 TopoDS_Shape tds = Copy.Shape();
3376 if( tds.IsNull() ) {
3377 THROW_SALOME_CORBA_EXCEPTION("Orientation aborted : null shape", SALOME::BAD_PARAM);
3380 if( tds.Orientation() == TopAbs_FORWARD)
3381 tds.Orientation(TopAbs_REVERSED) ;
3383 tds.Orientation(TopAbs_FORWARD) ;
3385 result = CreateObject(tds);
3386 InsertInLabelOneArgument(shape, aShape, tds, result, myCurrentOCAFDoc) ;
3392 //==================================================================================
3393 // function : GetReferencedObjects()
3395 //==================================================================================
3396 GEOM::GEOM_Gen::ListOfIOR* GEOM_Gen_i::GetReferencedObjects(GEOM::GEOM_Shape_ptr shape)
3398 GEOM::GEOM_Gen::ListOfIOR_var aList = new GEOM::GEOM_Gen::ListOfIOR;
3401 if (shape->_is_nil()) return aList._retn();
3403 Standard_CString entry = shape->ShapeId();
3405 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), entry, Lab);
3407 Handle(TDataStd_Name) Att;
3408 Lab.FindAttribute(TDataStd_Name::GetID(),Att);
3410 TDF_ChildIterator ChildIterator(Lab);
3411 if (ChildIterator.More()) {
3412 TDF_Label L = ChildIterator.Value();
3413 Handle(TDataStd_Name) Att;
3414 L.FindAttribute(TDataStd_Name::GetID(),Att);
3415 if (Att->Get().IsEqual(TCollection_ExtendedString("Arguments")) ) {
3417 TDF_ChildIterator ChildIterator1(L);
3420 while (ChildIterator1.More()) {
3421 TDF_Label L = ChildIterator1.Value();
3423 Handle(TDF_Reference) Ref;
3424 if (L.FindAttribute(TDF_Reference::GetID(),Ref)) {
3427 ChildIterator1.Next();
3431 TDF_ChildIterator ChildIterator2(L);
3432 while (ChildIterator2.More()) {
3433 TDF_Label L = ChildIterator2.Value();
3434 Handle(TDF_Reference) Ref;
3435 if (L.FindAttribute(TDF_Reference::GetID(),Ref)) {
3436 TDF_Label L = Ref->Get();
3438 Handle(TDataStd_Name) Att;
3439 L.FindAttribute(TDataStd_Name::GetID(),Att);
3440 TCollection_AsciiString nameIOR (Att->Get()) ;
3441 aList[i] = strdup( nameIOR.ToCString() );
3445 ChildIterator2.Next();
3449 return aList._retn();
3452 //==================================================================================
3453 // function : GetObjects()
3455 //==================================================================================
3456 GEOM::GEOM_Gen::ListOfIOR* GEOM_Gen_i::GetObjects(GEOM::GEOM_Shape_ptr shape)
3458 GEOM::GEOM_Gen::ListOfIOR_var aList = new GEOM::GEOM_Gen::ListOfIOR;
3461 Standard_CString entry = shape->ShapeId();
3463 TDF_Tool::Label(myCurrentOCAFDoc->GetData(), entry, Lab);
3465 Handle(TDataStd_Name) Att;
3466 Lab.FindAttribute(TDataStd_Name::GetID(),Att);
3468 TDF_ChildIterator ChildIterator(Lab);
3470 while (ChildIterator.More()) {
3471 TDF_Label L = ChildIterator.Value();
3472 Handle(TDataStd_Name) Att;
3473 L.FindAttribute(TDataStd_Name::GetID(),Att);
3475 if (!Att->Get().IsEqual(TCollection_ExtendedString("Arguments")) ) {
3478 ChildIterator.Next();
3483 TDF_ChildIterator ChildIterator1(Lab);
3484 while (ChildIterator1.More()) {
3485 TDF_Label L = ChildIterator1.Value();
3486 Handle(TDataStd_Name) Att;
3487 L.FindAttribute(TDataStd_Name::GetID(),Att);
3489 if (!Att->Get().IsEqual(TCollection_ExtendedString("Arguments")) ) {
3490 TCollection_AsciiString nameIOR (Att->Get());
3491 aList[i] = strdup( nameIOR.ToCString() );
3494 ChildIterator1.Next();
3496 return aList._retn();
3500 //==================================================================================
3501 // function : Import
3502 // purpose : Import shape from a BREP file
3503 //==================================================================================
3504 GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportBREP(const char* filename)
3505 throw (SALOME::SALOME_Exception)
3508 GEOM::GEOM_Shape_var result ;
3511 BRep_Builder aBuilder;
3512 BRepTools::Read(tds, strdup(filename), aBuilder) ;
3514 THROW_SALOME_CORBA_EXCEPTION("Import BRep aborted", SALOME::BAD_PARAM);
3517 catch(Standard_Failure) {
3518 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportBREP", SALOME::BAD_PARAM);
3521 result = CreateObject(tds) ;
3522 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3523 result->ShapeId(entry);
3528 //================================================================================
3529 // function : MakePlane()
3530 // purpose : Make a plane topology (non infinite)
3531 //================================================================================
3532 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePlane(const GEOM::PointStruct& pstruct,
3533 const GEOM::DirStruct& dstruct,
3534 CORBA::Double trimsize)
3535 throw (SALOME::SALOME_Exception)
3537 GEOM::GEOM_Shape_var result ;
3541 gp_Pnt aPoint(pstruct.x, pstruct.y, pstruct.z) ;
3542 gp_Dir aDirection(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
3543 /* we make a trimmed plane */
3544 gp_Pln gplane(aPoint, aDirection) ;
3545 tds = BRepBuilderAPI_MakeFace(gplane, -trimsize, +trimsize, -trimsize, +trimsize) ;
3547 catch(Standard_Failure) {
3548 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePlane", SALOME::BAD_PARAM);
3552 THROW_SALOME_CORBA_EXCEPTION("Make Plane aborted : null shape", SALOME::BAD_PARAM);
3555 result = CreateObject(tds) ;
3556 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3557 result->ShapeId(entry);
3561 //=================================================================================
3562 // function : MakeVertex()
3563 // purpose : Create a Vertex topology.
3564 //=================================================================================
3565 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeVertex(CORBA::Double x,
3568 throw (SALOME::SALOME_Exception)
3571 GEOM::GEOM_Shape_var result ;
3573 TopoDS_Shape tds = BRepBuilderAPI_MakeVertex(P).Shape();
3575 THROW_SALOME_CORBA_EXCEPTION("Make Vertex/Point aborted", SALOME::BAD_PARAM);
3577 result = CreateObject(tds) ;
3578 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3579 result->ShapeId(entry);
3584 //=================================================================================
3585 // function : MakeFace()
3587 //=================================================================================
3588 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFace( GEOM::GEOM_Shape_ptr wire,
3589 CORBA::Boolean wantplanarface )
3590 throw (SALOME::SALOME_Exception)
3592 GEOM::GEOM_Shape_var result ;
3593 TopoDS_Shape aShape;
3597 aShape = GetTopoShape(wire) ;
3598 if( aShape.IsNull() || aShape.ShapeType() != TopAbs_WIRE ) {
3599 THROW_SALOME_CORBA_EXCEPTION("MakeFace aborted : null or inappropriate shape", SALOME::BAD_PARAM);
3601 TopoDS_Wire W = TopoDS::Wire(aShape) ;
3602 tds = BRepBuilderAPI_MakeFace(W, wantplanarface).Shape() ;
3603 if( !tds.IsNull() ) {
3604 result = CreateObject(tds) ;
3605 InsertInLabelOneArgument(aShape, wire, tds, result, myCurrentOCAFDoc) ;
3608 THROW_SALOME_CORBA_EXCEPTION("Null result in GEOM_Gen_i::MakeFace", SALOME::BAD_PARAM);
3611 catch (Standard_Failure) {
3612 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeFace", SALOME::BAD_PARAM);
3618 //================================================================================
3619 // function : MakeLine
3620 // purpose : Make a Line topology
3621 //================================================================================
3622 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeLine(const GEOM::PointStruct& pstruct,
3623 const GEOM::DirStruct& dstruct)
3624 throw (SALOME::SALOME_Exception)
3626 GEOM::GEOM_Shape_var result ;
3627 gp_Pnt P1(pstruct.x, pstruct.y, pstruct.z);
3628 gp_Pnt P2(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
3632 tds = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
3634 catch(Standard_Failure) {
3635 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeLine", SALOME::BAD_PARAM);
3638 if ( tds.IsNull() ) {
3639 THROW_SALOME_CORBA_EXCEPTION("Make Line aborted : null shape", SALOME::BAD_PARAM);
3642 result = CreateObject(tds) ;
3643 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3644 result->ShapeId(entry);
3650 //================================================================================
3651 // function : MakeVector()
3652 // purpose : Make a vector
3653 //================================================================================
3654 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeVector(const GEOM::PointStruct& pstruct1,
3655 const GEOM::PointStruct& pstruct2)
3656 throw (SALOME::SALOME_Exception)
3658 GEOM::GEOM_Shape_var result ;
3662 gp_Pnt P1(pstruct1.x, pstruct1.y, pstruct1.z);
3663 gp_Pnt P2(pstruct2.x, pstruct2.y, pstruct2.z) ;
3664 tds = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
3666 catch(Standard_Failure) {
3667 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeVector", SALOME::BAD_PARAM);
3670 if ( tds.IsNull() ) {
3671 THROW_SALOME_CORBA_EXCEPTION("Make Vector aborted : null shape", SALOME::BAD_PARAM);
3674 result = CreateObject(tds) ;
3675 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3676 result->ShapeId(entry);
3682 //================================================================================
3683 // function : MakeCircle()
3685 //================================================================================
3686 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCircle(const GEOM::PointStruct& pstruct,
3687 const GEOM::DirStruct& dstruct,
3688 CORBA::Double radius)
3689 throw (SALOME::SALOME_Exception)
3691 GEOM::GEOM_Shape_var result;
3695 gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ;
3696 gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ;
3698 gp_Circ circ( axis, radius);
3699 BRepBuilderAPI_MakeEdge MakeEdge( circ );
3700 tds = MakeEdge.Edge();
3702 catch(Standard_Failure) {
3703 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeCircle", SALOME::BAD_PARAM);
3706 THROW_SALOME_CORBA_EXCEPTION("Make Circle aborted", SALOME::BAD_PARAM);
3708 result = CreateObject(tds);
3709 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3710 result->ShapeId(entry);
3714 //================================================================================
3715 // function : MakeArc()
3716 // purpose : make an arc of circle from pInit to pEnd and passing on pCircle
3717 //================================================================================
3718 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeArc(const GEOM::PointStruct& pInit,
3719 const GEOM::PointStruct& pCircle,
3720 const GEOM::PointStruct& pEnd)
3721 throw (SALOME::SALOME_Exception)
3723 GEOM::GEOM_Shape_var result;
3725 gp_Pnt pI(pInit.x, pInit.y, pInit.z) ;
3726 gp_Pnt pC(pCircle.x, pCircle.y, pCircle.z) ;
3727 gp_Pnt pE(pEnd.x, pEnd.y, pEnd.z) ;
3729 GC_MakeArcOfCircle arc( pI, pC, pE ) ;
3730 if( !arc.IsDone() ) {
3731 THROW_SALOME_CORBA_EXCEPTION("Arc not done", SALOME::BAD_PARAM);
3733 BRepBuilderAPI_MakeEdge MakeEdge( arc );
3734 TopoDS_Shape tds = MakeEdge.Edge();
3736 THROW_SALOME_CORBA_EXCEPTION("Null result : arc not done", SALOME::BAD_PARAM);
3739 result = CreateObject(tds);
3740 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
3741 result->ShapeId(entry);
3744 catch(Standard_Failure) {
3745 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeArc", SALOME::BAD_PARAM);
3752 //=================================================================================
3753 // function : MakeTranslation()
3754 // purpose : Translate a 3D shape
3755 //=================================================================================
3756 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeTranslation( GEOM::GEOM_Shape_ptr myShape,
3760 throw (SALOME::SALOME_Exception)
3762 GEOM::GEOM_Shape_var result ;
3763 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3764 if( aShape.IsNull() ) {
3765 THROW_SALOME_CORBA_EXCEPTION("Translation aborted : null shape", SALOME::BAD_PARAM);
3767 gp_Vec theVector(x,y,z) ;
3768 gp_Trsf theTransformation ;
3769 theTransformation.SetTranslation(theVector) ;
3770 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
3771 TopoDS_Shape tds = myBRepTransformation.Shape() ;
3773 result = CreateObject(tds) ;
3774 if( CORBA::is_nil(result) ) {
3775 THROW_SALOME_CORBA_EXCEPTION("Translation aborted : null result", SALOME::BAD_PARAM);
3777 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3782 //=================================================================================
3783 // function : MakeMultiTranslation1D()
3784 // purpose : Multi-Translate a 3D shape
3785 //=================================================================================
3786 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiTranslation1D( GEOM::GEOM_Shape_ptr myShape,
3787 const GEOM::DirStruct& dir,
3789 CORBA::Short nbtimes )
3790 throw (SALOME::SALOME_Exception)
3792 GEOM::GEOM_Shape_var result ;
3795 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3796 if( aShape.IsNull() )
3797 THROW_SALOME_CORBA_EXCEPTION("MakeMultiTranslation1D aborted : null shape", SALOME::BAD_PARAM);
3802 gp_Trsf theTransformation ;
3804 gp_Vec Vec( dir.PS.x, dir.PS.y, dir.PS.z ) ;
3806 TopoDS_Compound compound;
3808 B.MakeCompound( compound );
3810 for ( i = 0; i < nbtimes; i++ ) {
3811 DX = i * step * Vec.X() ;
3812 DY = i * step * Vec.Y() ;
3813 DZ = i * step * Vec.Z() ;
3814 myVec.SetCoord( DX, DY, DZ ) ;
3815 theTransformation.SetTranslation(myVec) ;
3816 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
3817 B.Add( compound, myBRepTransformation.Shape() );
3820 result = CreateObject(tds) ;
3822 catch (Standard_Failure) {
3823 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMultiTranslation1D", SALOME::BAD_PARAM);
3826 if( CORBA::is_nil(result) ) {
3827 THROW_SALOME_CORBA_EXCEPTION("MakeMultiTranslation1D aborted : null result", SALOME::BAD_PARAM);
3829 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3834 //=================================================================================
3835 // function : MakeMultiTranslation2D()
3836 // purpose : Multi-Translate a 3D shape
3837 //=================================================================================
3838 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiTranslation2D( GEOM::GEOM_Shape_ptr myShape,
3839 const GEOM::DirStruct& dir1,
3840 CORBA::Double step1,
3841 CORBA::Short nbtimes1,
3842 const GEOM::DirStruct& dir2,
3843 CORBA::Double step2,
3844 CORBA::Short nbtimes2 )
3845 throw (SALOME::SALOME_Exception)
3847 GEOM::GEOM_Shape_var result ;
3850 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3851 if( aShape.IsNull() ) {
3852 THROW_SALOME_CORBA_EXCEPTION("MakeMultiTranslation2D aborted : null shape", SALOME::BAD_PARAM);
3858 gp_Trsf theTransformation ;
3860 gp_Vec Vec1( dir1.PS.x, dir1.PS.y, dir1.PS.z ) ;
3862 gp_Vec Vec2( dir2.PS.x, dir2.PS.y, dir2.PS.z ) ;
3864 TopoDS_Compound compound;
3866 B.MakeCompound( compound );
3868 for ( i = 0; i < nbtimes1; i++ ) {
3869 for ( j = 0; j < nbtimes2; j++ ) {
3870 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X() ;
3871 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y() ;
3872 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z() ;
3873 myVec.SetCoord( DX, DY, DZ ) ;
3874 theTransformation.SetTranslation(myVec) ;
3875 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
3876 B.Add( compound, myBRepTransformation.Shape() );
3880 result = CreateObject(tds) ;
3882 catch(Standard_Failure) {
3883 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMultiTranslation2D", SALOME::BAD_PARAM);
3886 if( CORBA::is_nil(result) ) {
3887 THROW_SALOME_CORBA_EXCEPTION("MakeMultiTranslation2D aborted : null result", SALOME::BAD_PARAM);
3889 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3894 //=================================================================================
3895 // function : MakeMultiRotation1D()
3896 // purpose : Multi-Rotate a 3D shape
3897 //=================================================================================
3898 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiRotation1D( GEOM::GEOM_Shape_ptr myShape,
3899 const GEOM::DirStruct& dir,
3900 const GEOM::PointStruct& loc,
3901 CORBA::Short nbtimes)
3902 throw (SALOME::SALOME_Exception)
3904 GEOM::GEOM_Shape_var result ;
3906 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3907 if( aShape.IsNull() ) {
3908 THROW_SALOME_CORBA_EXCEPTION("MakeMultiRotation1D aborted : null shape", SALOME::BAD_PARAM);
3914 gp_Pnt P(loc.x, loc.y, loc.z) ;
3915 gp_Dir D(dir.PS.x, dir.PS.y, dir.PS.z) ;
3918 double angle = 360.0/nbtimes ;
3919 gp_Trsf theTransformation ;
3920 TopoDS_Compound compound;
3922 B.MakeCompound( compound );
3924 for ( i = 0; i < nbtimes; i++ ) {
3925 theTransformation.SetRotation(AX1, i*angle*PI180) ;
3926 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
3927 B.Add( compound, myBRepTransformation.Shape() );
3930 result = CreateObject(tds) ;
3932 catch(Standard_Failure) {
3933 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMultiRotation1D", SALOME::BAD_PARAM);
3936 if( CORBA::is_nil(result) ) {
3937 THROW_SALOME_CORBA_EXCEPTION("MakeMultiRotation1D aborted : null result", SALOME::BAD_PARAM);
3939 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
3944 //=================================================================================
3945 // function : MakeMultiRotation2D()
3946 // purpose : Multi-Rotate a 3D shape
3947 //=================================================================================
3948 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiRotation2D( GEOM::GEOM_Shape_ptr myShape,
3949 const GEOM::DirStruct& dir,
3950 const GEOM::PointStruct& loc,
3952 CORBA::Short nbtimes1,
3954 CORBA::Short nbtimes2 )
3955 throw (SALOME::SALOME_Exception)
3957 GEOM::GEOM_Shape_var result ;
3959 TopoDS_Shape aShape = GetTopoShape(myShape) ;
3960 if( aShape.IsNull() ) {
3961 THROW_SALOME_CORBA_EXCEPTION("MakeMultiRotation2D aborted : null shape", SALOME::BAD_PARAM);
3968 gp_Pnt P(loc.x, loc.y, loc.z) ;
3969 gp_Dir D(dir.PS.x, dir.PS.y, dir.PS.z) ;
3971 gp_Trsf theTransformation1 ;
3972 gp_Trsf theTransformation2 ;
3974 GProp_GProps System ;
3976 if ( aShape.ShapeType() == TopAbs_VERTEX) {
3977 P1 = BRep_Tool::Pnt(TopoDS::Vertex( aShape ));
3979 else if ( aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE ) {
3980 BRepGProp::LinearProperties(aShape, System);
3981 P1 = System.CentreOfMass() ;
3983 else if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL ) {
3984 BRepGProp::SurfaceProperties(aShape, System);
3985 P1 = System.CentreOfMass() ;
3988 BRepGProp::VolumeProperties(aShape, System);
3989 P1 = System.CentreOfMass() ;
3992 Handle(Geom_Line) Line = new Geom_Line(AX1);
3993 gp_Pnt P2 = GeomAPI_ProjectPointOnCurve( P1, Line ) ;
3995 if ( P1.IsEqual(P2, Precision::Confusion() ) )
3996 THROW_SALOME_CORBA_EXCEPTION("Points are confused", SALOME::BAD_PARAM);
3998 gp_Vec Vec(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()) ;
4002 TopoDS_Compound compound;
4004 B.MakeCompound( compound );
4006 for ( i = 0; i < nbtimes2; i++ ) {
4007 for ( j = 0; j < nbtimes1; j++ ) {
4008 DX = i * step * Vec.X() ;
4009 DY = i * step * Vec.Y() ;
4010 DZ = i * step * Vec.Z() ;
4011 myVec.SetCoord( DX, DY, DZ ) ;
4012 theTransformation1.SetTranslation(myVec) ;
4013 theTransformation2.SetRotation(AX1, j*ang*PI180) ;
4014 BRepBuilderAPI_Transform myBRepTransformation1(aShape, theTransformation1, Standard_False) ;
4015 BRepBuilderAPI_Transform myBRepTransformation2(myBRepTransformation1.Shape(), theTransformation2, Standard_False) ;
4016 B.Add( compound, myBRepTransformation2.Shape() );
4020 result = CreateObject(tds) ;
4022 catch(Standard_Failure) {
4023 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMultiRotation2D", SALOME::BAD_PARAM);
4026 if( CORBA::is_nil(result) ) {
4027 THROW_SALOME_CORBA_EXCEPTION("MakeMultiRotation2D aborted : null result", SALOME::BAD_PARAM);
4029 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4034 //=================================================================================
4035 // function : MakeCopy()
4036 // purpose : Copy a 3D shape
4037 //=================================================================================
4038 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCopy( GEOM::GEOM_Shape_ptr Shape)
4039 throw (SALOME::SALOME_Exception)
4041 GEOM::GEOM_Shape_var result ;
4043 TopoDS_Shape aShape = GetTopoShape(Shape) ;
4044 if(aShape.IsNull() ) {
4045 THROW_SALOME_CORBA_EXCEPTION("Copy aborted : null shape during operation", SALOME::BAD_PARAM);
4047 BRepBuilderAPI_Copy Copy(aShape);
4048 if( Copy.IsDone() ) {
4050 result = CreateObject(tds);
4051 InsertInLabelOneArgument(aShape, Shape, tds, result, myCurrentOCAFDoc) ;
4058 //=================================================================================
4059 // function : MakeMirrorByPlane()
4060 // purpose : build a shape by symmetry of 'myShape' with 'shapePlane' in argument
4061 //=================================================================================
4062 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMirrorByPlane(GEOM::GEOM_Shape_ptr myShape,
4063 GEOM::GEOM_Shape_ptr shapePlane)
4064 throw (SALOME::SALOME_Exception)
4066 GEOM::GEOM_Shape_var result ;
4068 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4069 TopoDS_Shape aShapePlane = GetTopoShape(shapePlane) ;
4070 if( aShape.IsNull() || aShapePlane.IsNull() ) {
4071 THROW_SALOME_CORBA_EXCEPTION("Mirror aborted : null shape argument", SALOME::BAD_PARAM);
4075 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(aShapePlane)) ;
4076 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf) ;
4077 const gp_Ax3 pos = myPlane->Position() ;
4078 const gp_Pnt loc = pos.Location() ; /* location of the plane */
4079 const gp_Dir dir = pos.Direction() ; /* Main direction of the plane (Z axis) */
4081 /* plane used for mirroring */
4082 gp_Ax2 pln(loc, dir) ;
4083 gp_Trsf theTransformation ;
4084 theTransformation.SetMirror(pln) ;
4085 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
4087 tds = myBRepTransformation.Shape() ;
4089 THROW_SALOME_CORBA_EXCEPTION("Mirror aborted", SALOME::BAD_PARAM);
4092 catch(Standard_Failure) {
4093 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeMirrorByPlane", SALOME::BAD_PARAM);
4096 result = CreateObject(tds) ;
4098 /* Insert arguments in ocaf */
4099 GEOM::GEOM_Gen::ListOfIOR_var ListShapes = new GEOM::GEOM_Gen::ListOfIOR;
4100 ListShapes->length(2);
4101 ListShapes[0] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(myShape)) ;
4102 ListShapes[1] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(shapePlane)) ;
4103 InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
4109 //=================================================================================
4110 // function : MakeRotation()
4111 // purpose : Rotation of a 3D shape around an axis
4112 //=================================================================================
4113 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeRotation( GEOM::GEOM_Shape_ptr myShape,
4114 const GEOM::AxisStruct& axis,
4115 CORBA::Double angle)
4116 throw (SALOME::SALOME_Exception)
4118 GEOM::GEOM_Shape_var result ;
4120 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4121 if( aShape.IsNull() ) {
4122 THROW_SALOME_CORBA_EXCEPTION("Rotation aborted : null shape during operation", SALOME::BAD_PARAM);
4126 gp_Pnt P(axis.x, axis.y, axis.z) ;
4127 gp_Dir D(axis.vx, axis.vy, axis.vz) ;
4130 gp_Trsf theTransformation ;
4131 theTransformation.SetRotation(AX, angle) ;
4132 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
4133 tds = myBRepTransformation.Shape() ;
4135 catch(Standard_Failure) {
4136 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeRotation", SALOME::BAD_PARAM);
4139 if ( !tds.IsNull() ) {
4140 result = CreateObject(tds) ;
4141 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4147 //=================================================================================
4148 // function : MakeScaleTransform()
4149 // purpose : Make a shape multipling another by a scale factor
4150 //=================================================================================
4151 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeScaleTransform(GEOM::GEOM_Shape_ptr myShape,
4152 const GEOM::PointStruct& theCenterOfScale,
4153 CORBA::Double factor)
4154 throw (SALOME::SALOME_Exception)
4156 GEOM::GEOM_Shape_var result ;
4158 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4159 if( aShape.IsNull() ) {
4160 THROW_SALOME_CORBA_EXCEPTION("Scale aborted : null shape during operation", SALOME::BAD_PARAM);
4164 gp_Pnt Pcenter(theCenterOfScale.x, theCenterOfScale.y, theCenterOfScale.z) ;
4165 gp_Trsf theTransformation ;
4166 theTransformation.SetScale(Pcenter, factor) ;
4167 BRepBuilderAPI_Transform myBRepTransformation(aShape, theTransformation, Standard_False) ;
4168 tds = myBRepTransformation.Shape() ;
4170 catch(Standard_Failure) {
4171 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeScaleTransform", SALOME::BAD_PARAM);
4174 if ( !tds.IsNull() ) {
4175 result = CreateObject(tds) ;
4176 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4182 //=================================================================================
4183 // function : MakeCompound()
4184 // purpose : Make a compound from a list containing one or more shapes
4185 //=================================================================================
4186 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCompound( const GEOM::GEOM_Gen::ListOfIOR& ListShapes )
4187 throw (SALOME::SALOME_Exception)
4189 GEOM::GEOM_Shape_var result ;
4191 BRep_Builder aBuilder;
4192 aBuilder.MakeCompound(C) ;
4194 for ( unsigned int i = 0; i < ListShapes.length(); i++) {
4195 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[i] );
4196 TopoDS_Shape Shape = GetTopoShape(aShape) ;
4197 if( Shape.IsNull() ) {
4198 THROW_SALOME_CORBA_EXCEPTION("Compound aborted : null shape during operation", SALOME::BAD_PARAM);
4200 aBuilder.Add(C, Shape) ;
4204 THROW_SALOME_CORBA_EXCEPTION("Null result : Compound operation aborted", SALOME::BAD_PARAM);
4207 result = CreateObject(C) ;
4208 InsertInLabelMoreArguments(C, result, ListShapes, myCurrentOCAFDoc) ;
4215 //================================================================================
4216 // function : MakeEdge()
4217 // purpose : Make a linear edge with 2 points
4218 //================================================================================
4219 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeEdge(const GEOM::PointStruct& pstruct1,
4220 const GEOM::PointStruct& pstruct2)
4221 throw (SALOME::SALOME_Exception)
4223 GEOM::GEOM_Shape_var result ;
4227 gp_Pnt P1(pstruct1.x, pstruct1.y, pstruct1.z);
4228 gp_Pnt P2(pstruct2.x, pstruct2.y, pstruct2.z) ;
4229 tds = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
4231 THROW_SALOME_CORBA_EXCEPTION("MakeEdge aborted : null result", SALOME::BAD_PARAM);
4233 catch (Standard_Failure) {
4234 THROW_SALOME_CORBA_EXCEPTION("Exception catched in MakeEdge", SALOME::BAD_PARAM);
4237 result = CreateObject(tds) ;
4238 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
4239 result->ShapeId(entry);
4245 //=================================================================================
4246 // function : MakeWire()
4247 // purpose : Make a wire from a list containing one or more edges or wires that can
4249 //=================================================================================
4250 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeWire( const GEOM::GEOM_Gen::ListOfIOR& ListShapes )
4251 throw (SALOME::SALOME_Exception)
4253 GEOM::GEOM_Shape_var result ;
4254 BRepBuilderAPI_MakeWire MW ;
4255 TopoDS_Shape tds, Shape ;
4258 for ( unsigned int i = 0; i < ListShapes.length(); i++) {
4259 GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[i] );
4260 Shape = GetTopoShape(aShape) ;
4261 if( Shape.IsNull() ) {
4262 THROW_SALOME_CORBA_EXCEPTION("MakeWire aborted : null shape during operation", SALOME::BAD_PARAM);
4264 if( Shape.ShapeType() == TopAbs_EDGE )
4265 MW.Add( TopoDS::Edge(Shape) ) ;
4266 if (Shape.ShapeType() == TopAbs_WIRE )
4267 MW.Add( TopoDS::Wire(Shape) ) ;
4272 catch(Standard_Failure) {
4273 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeWire", SALOME::BAD_PARAM);
4276 if( tds.IsNull() ) {
4277 THROW_SALOME_CORBA_EXCEPTION("Make Wire operation aborted : null result", SALOME::BAD_PARAM);
4280 result = CreateObject(tds) ;
4281 InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
4288 //=================================================================================
4289 // function : MakeRevolution()
4291 //=================================================================================
4292 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeRevolution(GEOM::GEOM_Shape_ptr myShape,
4293 const GEOM::AxisStruct& axis,
4295 throw (SALOME::SALOME_Exception)
4297 GEOM::GEOM_Shape_var result ;
4299 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4300 if( aShape.IsNull() ) {
4301 THROW_SALOME_CORBA_EXCEPTION("Revolution aborted : null shape", SALOME::BAD_PARAM);
4304 gp_Pnt P(axis.x, axis.y, axis.z) ;
4305 gp_Dir D(axis.vx, axis.vy, axis.vz);
4307 tds = BRepPrimAPI_MakeRevol(aShape, AX, angle);
4309 catch(Standard_Failure) {
4310 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeRevolution", SALOME::BAD_PARAM);
4313 if( tds.IsNull() ) {
4314 THROW_SALOME_CORBA_EXCEPTION("Revolution aborted", SALOME::BAD_PARAM);
4316 result = CreateObject(tds) ;
4317 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4322 //=================================================================================
4323 // function : MakePipe()
4324 // purpose : Create a shape by sweeping a baseShape along a pathShape
4325 //=================================================================================
4326 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePipe( GEOM::GEOM_Shape_ptr pathShape,
4327 GEOM::GEOM_Shape_ptr baseShape )
4328 throw (SALOME::SALOME_Exception)
4330 GEOM::GEOM_Shape_var result ;
4333 TopoDS_Shape pathTds = GetTopoShape(pathShape) ;
4334 TopoDS_Shape baseTds = GetTopoShape(baseShape) ;
4336 if( baseTds.IsNull() || pathTds.IsNull() ) {
4337 THROW_SALOME_CORBA_EXCEPTION("MakePipe aborted : null shape argument", SALOME::BAD_PARAM);
4340 if( pathTds.ShapeType() == TopAbs_WIRE ) {
4341 aWire = TopoDS::Wire(pathTds) ;
4344 if ( pathTds.ShapeType() == TopAbs_EDGE ) {
4345 TopoDS_Edge aEdge = TopoDS::Edge(pathTds) ;
4346 aWire = BRepBuilderAPI_MakeWire(aEdge);
4349 THROW_SALOME_CORBA_EXCEPTION("MakePipe aborted : bad shape type", SALOME::BAD_PARAM);
4354 tds = BRepOffsetAPI_MakePipe(aWire, baseTds) ;
4356 catch(Standard_Failure) {
4357 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePipe", SALOME::BAD_PARAM);
4360 if ( !BRepAlgoAPI::IsValid(tds) ) {
4361 THROW_SALOME_CORBA_EXCEPTION("MakePipe aborted : non valid shape result", SALOME::BAD_PARAM);
4364 result = CreateObject(tds) ;
4366 /* Insert arguments in ocaf */
4367 GEOM::GEOM_Gen::ListOfIOR_var ListShapes = new GEOM::GEOM_Gen::ListOfIOR;
4368 ListShapes->length(2);
4369 ListShapes[0] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(pathShape)) ;
4370 ListShapes[1] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(baseShape)) ;
4371 InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
4377 //=================================================================================
4378 // function : MakePrism()
4379 // purpose : uses myShape as base and the vector P1 to P2
4380 //=================================================================================
4381 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePrism( GEOM::GEOM_Shape_ptr myShape,
4382 const GEOM::PointStruct& P1,
4383 const GEOM::PointStruct& P2 )
4384 throw (SALOME::SALOME_Exception)
4386 GEOM::GEOM_Shape_var result ;
4388 TopoDS_Shape aShape = GetTopoShape(myShape) ;
4389 if( aShape.IsNull() ) {
4390 THROW_SALOME_CORBA_EXCEPTION("Prism aborted : null shape operation", SALOME::BAD_PARAM);
4394 gp_Vec Vector (P2.x - P1.x, P2.y - P1.y, P2.z - P1.z) ;
4395 tds = BRepPrimAPI_MakePrism(aShape, Vector, Standard_False).Shape() ;
4397 catch(Standard_Failure) {
4398 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePipe", SALOME::BAD_PARAM);
4401 if ( tds.IsNull() ) {
4402 THROW_SALOME_CORBA_EXCEPTION("Prism aborted", SALOME::BAD_PARAM);
4405 result = CreateObject(tds) ;
4406 InsertInLabelOneArgument(aShape, myShape, tds, result, myCurrentOCAFDoc) ;
4412 //=================================================================================
4413 // function : MakeCDG()
4414 // purpose : Create a CDG topology.
4415 //=================================================================================
4416 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCDG(GEOM::GEOM_Shape_ptr aShape)
4417 throw (SALOME::SALOME_Exception)
4419 GEOM::GEOM_Shape_var result ;
4421 TopoDS_Shape shape = GetTopoShape(aShape) ;
4422 GProp_GProps System;
4423 gp_Pnt myCenterMass ;
4425 if( shape.IsNull() ) {
4426 THROW_SALOME_CORBA_EXCEPTION("MakeCDG aborted : null shape argument", SALOME::BAD_PARAM);
4430 if ( shape.ShapeType() == TopAbs_VERTEX) {
4431 myCenterMass = BRep_Tool::Pnt(TopoDS::Vertex( shape ));
4433 else if ( shape.ShapeType() == TopAbs_EDGE || shape.ShapeType() == TopAbs_WIRE ) {
4434 BRepGProp::LinearProperties(shape, System);
4435 myCenterMass = System.CentreOfMass() ;
4437 else if ( shape.ShapeType() == TopAbs_FACE || shape.ShapeType() == TopAbs_SHELL ) {
4438 BRepGProp::SurfaceProperties(shape, System);
4439 myCenterMass = System.CentreOfMass() ;
4442 BRepGProp::VolumeProperties(shape, System);
4443 myCenterMass = System.CentreOfMass() ;
4446 tds = BRepBuilderAPI_MakeVertex(myCenterMass).Shape() ;
4448 catch(Standard_Failure) {
4449 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeCDG", SALOME::BAD_PARAM);
4452 if ( tds.IsNull() ) {
4453 THROW_SALOME_CORBA_EXCEPTION("Make CDG aborted : null shape result", SALOME::BAD_PARAM);
4456 result = CreateObject(tds) ;
4457 InsertInLabelOneArgument(shape, aShape, tds, result, myCurrentOCAFDoc) ;
4463 //=================================================================================
4464 // function : Archimede()
4466 //=================================================================================
4467 GEOM::GEOM_Shape_ptr GEOM_Gen_i::Archimede(GEOM::GEOM_Shape_ptr aShape,
4468 CORBA::Double aWeight,
4469 CORBA::Double aWaterDensity,
4470 CORBA::Double aMeshingDeflection)
4471 throw (SALOME::SALOME_Exception)
4473 GEOM::GEOM_Shape_var result;
4476 if (aWaterDensity != 0.)
4477 cste = aWeight/aWaterDensity;
4479 THROW_SALOME_CORBA_EXCEPTION("Water density is null", SALOME::BAD_PARAM);
4481 TopoDS_Shape shape = GetTopoShape(aShape) ;
4482 if( shape.IsNull() ) {
4483 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
4486 gp_Dir direct(0.0,0.0,1.0);
4487 gp_Pnt PosPlan(0.0,0.0,0.0);
4488 Geom_Plane PP (PosPlan,direct);
4489 Handle(Geom_Geometry) G = PP.Copy();
4490 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(G);
4492 gp_Dir Zdirection(0.0,0.0,1.0);
4493 VolumeSection VOL( shape, aMeshingDeflection);
4495 Handle (Geom_RectangularTrimmedSurface) SurfaceTrimmee;
4497 if(Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
4498 VOL.MakeRotation(direct);
4501 VOL.CenterOfGravity();
4502 SurfaceTrimmee = VOL.TrimSurf();
4503 Standard_Real Cote = VOL.Archimede( cste, aMeshingDeflection );
4507 VOL.getZ(Zmin,Zmax);
4508 double volume = VOL.CalculateVolume( Zmax ) * aWaterDensity;
4511 sprintf(msg, "shape sinks to the bottom : Weigth max = %.1f", volume);
4513 THROW_SALOME_CORBA_EXCEPTION(msg, SALOME::BAD_PARAM);
4516 SurfaceTrimmee=VOL.AjustePlan(SurfaceTrimmee,Cote,PosPlan);
4517 if(Zdirection.IsEqual(direct,Precision::Angular()) == Standard_False) {
4518 SurfaceTrimmee=VOL.InvMakeRotation(direct,SurfaceTrimmee);
4521 Standard_Real u1,u2,v1,v2;
4522 SurfaceTrimmee->Bounds(u1,u2,v1,v2);
4523 TopoDS_Face tirant = BRepBuilderAPI_MakeFace(SurfaceTrimmee, u1, u2, v1, v2);
4525 if (tirant.IsNull()) {
4526 THROW_SALOME_CORBA_EXCEPTION("Result is null", SALOME::BAD_PARAM);
4529 result = CreateObject(tirant);
4530 InsertInLabelOneArgument(shape, aShape, tirant, result, myCurrentOCAFDoc) ;
4536 //================================================================================
4537 // function : MakeFillet()
4538 // purpose : Create a cylinder topology
4539 //================================================================================
4540 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFillet( GEOM::GEOM_Shape_ptr shape,
4541 CORBA::Double radius,
4542 CORBA::Short ShapeType,
4543 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID )
4544 throw (SALOME::SALOME_Exception)
4546 GEOM::GEOM_Shape_var result;
4549 const TopoDS_Shape aShape = GetTopoShape(shape) ;
4550 if( aShape.IsNull() ) {
4551 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
4554 BRepFilletAPI_MakeFillet fill(aShape);
4558 if(ListOfID.length() == 0) {
4559 TopExp_Explorer Exp ( aShape, TopAbs_EDGE );
4560 for (Exp; Exp.More(); Exp.Next()) {
4561 TopoDS_Edge E =TopoDS::Edge(Exp.Current());
4564 for (int i = 1;i<=fill.NbContours();i++) {
4565 fill.SetRadius(radius,i);
4571 /* case selection */
4572 for ( unsigned int ind = 0; ind < ListOfID.length(); ind++ ) {
4574 if( GetShapeFromIndex( aShape, (TopAbs_ShapeEnum)ShapeType, ListOfID[ind], ss ) ) {
4575 TopoDS_Edge E = TopoDS::Edge(ss) ;
4579 for (int i = 1;i<=fill.NbContours();i++) {
4580 fill.SetRadius(radius,i);
4585 catch(Standard_Failure) {
4586 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeFillet", SALOME::BAD_PARAM);
4590 THROW_SALOME_CORBA_EXCEPTION("Make Fillet aborted", SALOME::BAD_PARAM);
4592 result = CreateObject(tds);
4593 InsertInLabelOneArgument(aShape, shape, tds, result, myCurrentOCAFDoc) ;
4599 //================================================================================
4600 // function : MakeChamfer
4601 // purpose : Create a Chamfer topology
4602 //================================================================================
4603 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeChamfer( GEOM::GEOM_Shape_ptr shape,
4606 CORBA::Short ShapeType,
4607 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID )
4608 throw (SALOME::SALOME_Exception)
4610 GEOM::GEOM_Shape_var result;
4613 const TopoDS_Shape aShape = GetTopoShape(shape) ;
4614 if( aShape.IsNull() ) {
4615 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
4618 BRepFilletAPI_MakeChamfer MC(aShape);
4622 TopTools_IndexedDataMapOfShapeListOfShape M;
4623 TopExp::MapShapesAndAncestors(aShape,TopAbs_EDGE,TopAbs_FACE,M);
4624 if(ListOfID.length() == 0) {
4625 for (int i = 1;i<=M.Extent();i++) {
4626 TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
4627 TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
4628 if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
4635 /* case selection */
4636 for ( unsigned int ind = 0; ind < ListOfID.length(); ind++ ) {
4638 if( GetShapeFromIndex( aShape, (TopAbs_ShapeEnum)ShapeType, ListOfID[ind], ss ) ) {
4639 TopoDS_Edge E = TopoDS::Edge( ss ) ;
4640 TopoDS_Face F = TopoDS::Face(M.FindFromKey(E).First());
4641 if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
4648 catch(Standard_Failure) {
4649 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeChamfer", SALOME::BAD_PARAM);
4653 THROW_SALOME_CORBA_EXCEPTION("Make Chamfer aborted", SALOME::BAD_PARAM);
4655 result = CreateObject(tds);
4656 InsertInLabelOneArgument(aShape, shape, tds, result, myCurrentOCAFDoc) ;
4661 //=================================================================================
4662 // function : CheckShape()
4664 //=================================================================================
4665 CORBA::Boolean GEOM_Gen_i::CheckShape(GEOM::GEOM_Shape_ptr shape)
4666 throw (SALOME::SALOME_Exception)
4668 TopoDS_Shape S = GetTopoShape(shape) ;
4670 THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM);
4673 BRepCheck_Analyzer ana(S,false);
4680 //=================================================================================
4681 // function : MakePlacedBox()
4683 //=================================================================================
4684 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePlacedBox(CORBA::Double x1, CORBA::Double y1, CORBA::Double z1,
4685 CORBA::Double delta1, CORBA::Double delta2, CORBA::Double delta3)
4686 throw (SALOME::SALOME_Exception)
4688 GEOM::GEOM_Shape_var result ;
4691 CORBA::Double x2, y2, z2 ;
4698 gp_Pnt P1(x1,y1,z1);
4699 gp_Pnt P2(x2,y2,z2);
4701 tds = BRepPrimAPI_MakeBox(P1,P2).Shape();
4703 catch(Standard_Failure) {
4704 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeBox", SALOME::BAD_PARAM);
4708 THROW_SALOME_CORBA_EXCEPTION("Make Box aborted : null shape", SALOME::BAD_PARAM);
4711 result = CreateObject(tds);
4712 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
4713 result->ShapeId(entry) ;
4718 //=================================================================================
4719 // function : MakePanel()
4721 //=================================================================================
4722 GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePanel(GEOM::GEOM_Shape_ptr shape,
4723 CORBA::Short directiontype,
4724 CORBA::Double delta)
4725 throw (SALOME::SALOME_Exception)
4727 GEOM::GEOM_Shape_var result ;
4729 TopoDS_Shape aShape = GetTopoShape(shape) ;
4731 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax ;
4732 GEOM::PointStruct pstruct1, pstruct2, pstruct3, pstruct4 ;
4734 if(aShape.IsNull() ) {
4735 THROW_SALOME_CORBA_EXCEPTION("MakePanel aborted : null shape during operation", SALOME::BAD_PARAM);
4739 BRepBndLib::Add(aShape,B);
4741 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
4743 switch (directiontype)
4746 pstruct1 = MakePointStruct( delta, aymin, azmin ) ;
4747 pstruct2 = MakePointStruct( delta, aymin, azmax ) ;
4748 pstruct3 = MakePointStruct( delta, aymax, azmax ) ;
4749 pstruct4 = MakePointStruct( delta, aymax, azmin ) ;
4752 pstruct1 = MakePointStruct( axmin, delta, azmin ) ;
4753 pstruct2 = MakePointStruct( axmin, delta, azmax ) ;
4754 pstruct3 = MakePointStruct( axmax, delta, azmax ) ;
4755 pstruct4 = MakePointStruct( axmax, delta, azmin ) ;
4758 pstruct1 = MakePointStruct( axmin, aymin, delta ) ;
4759 pstruct2 = MakePointStruct( axmin, aymax, delta ) ;
4760 pstruct3 = MakePointStruct( axmax, aymax, delta ) ;
4761 pstruct4 = MakePointStruct( axmax, aymin, delta ) ;
4767 GEOM::GEOM_Shape_ptr Edge1 = MakeEdge(pstruct1, pstruct2);
4768 GEOM::GEOM_Shape_ptr Edge2 = MakeEdge(pstruct2, pstruct3);
4769 GEOM::GEOM_Shape_ptr Edge3 = MakeEdge(pstruct3, pstruct4);
4770 GEOM::GEOM_Shape_ptr Edge4 = MakeEdge(pstruct4, pstruct1);
4772 GEOM::GEOM_Gen::ListOfIOR_var aList = new GEOM::GEOM_Gen::ListOfIOR;
4774 aList[0]=strdup(Edge1->Name());
4775 aList[1]=strdup(Edge2->Name());
4776 aList[2]=strdup(Edge3->Name());
4777 aList[3]=strdup(Edge4->Name());
4779 GEOM::GEOM_Shape_ptr aWire = MakeWire( aList );
4780 GEOM::GEOM_Shape_ptr aFace = MakeFace( aWire, true ) ;
4781 tds = GetTopoShape(aFace);
4784 catch(Standard_Failure) {
4785 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePanel", SALOME::BAD_PARAM);
4789 THROW_SALOME_CORBA_EXCEPTION("Make PanelsPartition aborted : null shape", SALOME::BAD_PARAM);
4792 result = CreateObject(tds);
4793 const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ;
4794 result->ShapeId(entry) ;
4800 void GEOM_Gen_i::ExportIGES(const char* filename,GEOM::GEOM_Shape_ptr theShape)
4801 throw (SALOME::SALOME_Exception)
4803 if (theShape->_is_nil())
4805 THROW_SALOME_CORBA_EXCEPTION("Export IGES aborted", SALOME::BAD_PARAM);
4807 TopoDS_Shape tds = GetTopoShape(theShape);
4810 THROW_SALOME_CORBA_EXCEPTION("Export IGES aborted", SALOME::BAD_PARAM);
4814 //VRV: OCC 4.0 migration
4815 IGESControl_Controller::Init();
4816 IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"),
4817 Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
4818 //VRV: OCC 4.0 migration
4822 char * aname = strdup(filename);
4823 Standard_Boolean result = ICW.Write( aname );
4826 catch(Standard_Failure)
4828 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ExportIGES", SALOME::BAD_PARAM);
4832 void GEOM_Gen_i::ExportBREP(const char* filename,GEOM::GEOM_Shape_ptr theShape)
4833 throw (SALOME::SALOME_Exception)
4835 if (theShape->_is_nil())
4837 THROW_SALOME_CORBA_EXCEPTION("Export BRep aborted", SALOME::BAD_PARAM);
4839 TopoDS_Shape tds = GetTopoShape(theShape);
4842 THROW_SALOME_CORBA_EXCEPTION("Export BRep aborted", SALOME::BAD_PARAM);
4846 char * aname = strdup(filename);
4847 Standard_Boolean result = BRepTools::Write(tds,aname);
4850 catch(Standard_Failure)
4852 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ExportBREP", SALOME::BAD_PARAM);
4856 void GEOM_Gen_i::ExportSTEP(const char* filename,GEOM::GEOM_Shape_ptr theShape)
4857 throw (SALOME::SALOME_Exception)
4859 if (theShape->_is_nil())
4861 THROW_SALOME_CORBA_EXCEPTION("Export STEP aborted", SALOME::BAD_PARAM);
4863 TopoDS_Shape tds = GetTopoShape(theShape);
4866 THROW_SALOME_CORBA_EXCEPTION("Export STEP aborted", SALOME::BAD_PARAM);
4870 IFSelect_ReturnStatus status ;
4871 //VRV: OCC 4.0 migration
4872 STEPControl_Writer aWriter;
4873 status = aWriter.Transfer( tds, STEPControl_ManifoldSolidBrep ) ;
4874 //VRV: OCC 4.0 migration
4875 if ( status == IFSelect_RetDone )
4877 char * aname = strdup(filename);
4878 status = aWriter.Write( aname ) ;
4882 catch(Standard_Failure)
4884 THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ExportBREP", SALOME::BAD_PARAM);
4889 //=====================================================================================
4891 //=====================================================================================
4894 PortableServer::ObjectId * GeometryEngine_factory(CORBA::ORB_ptr orb,
4895 PortableServer::POA_ptr poa,
4896 PortableServer::ObjectId * contId,
4897 const char *instanceName,
4898 const char * interfaceName)
4901 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
4903 myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
4905 return myGEOM_Gen_i->getId() ;