X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM%2FGEOM_Gen_i.cc;h=f07429df9bb4b351530f3f42f32b9a1864be0736;hb=6d5e9822fdeb14b60c55116fa6e6417b931d3533;hp=7b9ecff28bf167ae2c15a64d2ac4680ebdfb6a27;hpb=ecb53a73db547cbbb50f2df55faa344e3ad41594;p=modules%2Fgeom.git diff --git a/src/GEOM/GEOM_Gen_i.cc b/src/GEOM/GEOM_Gen_i.cc index 7b9ecff28..f07429df9 100644 --- a/src/GEOM/GEOM_Gen_i.cc +++ b/src/GEOM/GEOM_Gen_i.cc @@ -1,15 +1,37 @@ -using namespace std; -// File : GEOM_GEN_i.cc file -// Created : -// Author : Lucien PIGNOLONI -// Project : SALOME -// Copyright : OPEN CASCADE -// $Header$ +// GEOM GEOM : implementaion of GEOM_Gen.idl and GEOM_Shape.idl +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : GEOM_GEN_i.cc file +// Author : Lucien PIGNOLONI +// Module : GEOM +// $Header$ +using namespace std; #include "GEOM_Gen_i.hh" #include "Partition_Spliter.hxx" #include "Archimede_VolumeSection.hxx" +#include "Sketcher_Profile.hxx" #include "Utils_CorbaException.hxx" #include "utilities.h" @@ -22,18 +44,27 @@ using namespace std; #include #include +#include #include #include +#include +#include #include #include #include #include #include #include +#include #include #include +#if OCC_VERSION_MAJOR >= 5 +#include +#else #include +#endif +#include #include #include #include @@ -103,6 +134,7 @@ using namespace std; #include #include #include +#include #include #include #include @@ -128,6 +160,16 @@ using namespace std; #include CORBA_SERVER_HEADER(SALOMEDS_Attributes) +#include "Utils_ExceptHandlers.hxx" + +Standard_EXPORT static Standard_Boolean IsValid(const TopoDS_Shape& S) { +#if OCC_VERSION_MAJOR >= 5 + return BRepAlgo::IsValid(S); +#else + return BRepAlgoAPI::IsValid(S); +#endif +} + //============================================================================ // function : GEOM_Gen_i() // purpose : constructor to be called for servant creation. @@ -165,11 +207,12 @@ GEOM_Gen_i::~GEOM_Gen_i() { //============================================================================ char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, const char* IORString, - CORBA::Boolean isMultiFile) + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) { GEOM::GEOM_Shape_var aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(IORString)); if (!CORBA::is_nil(aShape)) { - return strdup(aShape->ShapeId()); + return aShape->ShapeId(); } return 0; } @@ -183,7 +226,8 @@ char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, //============================================================================ char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, const char* aLocalPersistentID, - CORBA::Boolean isMultiFile) + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) { SALOMEDS::Study_var myStudy = theSObject->GetStudy(); GetCurrentStudy(myStudy->StudyId()); @@ -194,6 +238,12 @@ char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, TCollection_ExtendedString MainIOR; TDF_Label Lab; TDF_Tool::Label(aDoc->GetData(), aPersRefString, Lab ); + + if (Lab.IsNull()) { + MESSAGE("Can not find label "<StudyId()); + THROW_SALOME_CORBA_EXCEPTION("Incorrect GEOM data loaded",SALOME::BAD_PARAM); + //return ""; empty IORs raise new problem: "display" in popup crashes + } Handle(TNaming_NamedShape) NS; Lab.FindAttribute( TNaming_NamedShape::GetID(), NS ); @@ -218,10 +268,10 @@ char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, TCollection_AsciiString entry; TDF_Tool::Entry(mainLabel,entry); - CORBA::String_var ent = strdup(entry.ToCString()); + CORBA::String_var ent = CORBA::string_dup(entry.ToCString()); /* Create the main object recursively */ - MainIOR = LocalPersistentIDToIOR(theSObject, ent, isMultiFile ) ; + MainIOR = LocalPersistentIDToIOR(theSObject, ent, isMultiFile, isASCII) ; } else { GC.ReturnNameIOR( mainLabel, MainIOR ); } @@ -322,6 +372,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, CORBA::Object_ptr theObject, const char* theName) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); SALOMEDS::SObject_var aResultSO; if(CORBA::is_nil(theObject)) return aResultSO; @@ -385,7 +436,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, aShapeName = "Vertex_"; } if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag()); - else aShapeName = TCollection_AsciiString(strdup(theName)); + else aShapeName = TCollection_AsciiString((char*)theName); //Set a name of the added shape anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName"); @@ -407,14 +458,16 @@ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, bool isMultiFile) { SALOMEDS::TMPFile_var aStreamFile; // Get a temporary directory to store a file - TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir(); + TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str(); // Create a list to store names of created files SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; aSeq->length(1); // Prepare a file name to open - TCollection_AsciiString aNameWithExt(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())); + TCollection_AsciiString aNameWithExt(""); + if (isMultiFile) + aNameWithExt = TCollection_AsciiString((char*)SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str()); aNameWithExt += TCollection_AsciiString("_GEOM.sgd"); - aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString()); + aSeq[0] = aNameWithExt.ToCString(); // Build a full file name of temporary file TCollection_AsciiString aFullName = aTmpDir + aNameWithExt; // Save GEOM component in this file @@ -427,30 +480,51 @@ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, return aStreamFile._retn(); } +SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile) { + SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile); + return aStreamFile._retn(); +} + + CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream, const char* theURL, bool isMultiFile) { + + if (theStream.length() <= 9) { + MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes "); + return false; + } + // Get a temporary directory for a file - TCollection_AsciiString aTmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir(); + TCollection_AsciiString aTmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str(); // Conver the byte stream theStream to a file and place it in tmp directory SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), isMultiFile); + // Prepare a file name to open - TCollection_AsciiString aNameWithExt(aSeq[0]); + TCollection_AsciiString aNameWithExt(""); + if (isMultiFile) + aNameWithExt = TCollection_AsciiString((char*)SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str()); + aNameWithExt += TCollection_AsciiString("_GEOM.sgd"); TCollection_AsciiString aFullName = aTmpDir + aNameWithExt; + // Open document if (myOCAFApp->Open(aFullName, myCurrentOCAFDoc) != CDF_RS_OK) return false; + // Remove the created file and tmp directory if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); SALOMEDS::Study_var Study = theComponent->GetStudy(); - TCollection_AsciiString name( strdup(Study->Name()) ); + TCollection_AsciiString name( Study->Name() ); int StudyID = Study->StudyId(); myStudyIDToDoc.Bind( StudyID, myCurrentOCAFDoc ); myStudyID = StudyID; + /* We clear all IOR (nameIOR) attributes of all objects before reconstruction */ /* This information will be setted when each object is reconstructed */ GEOMDS_Commands GC( myCurrentOCAFDoc->Main() ) ; @@ -459,6 +533,13 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, return true; } +CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile) { + return Load(theComponent, theStream, theURL, isMultiFile); +} + // //============================================================================ // // function : Save() // // purpose : save OCAF/Geom document @@ -466,7 +547,7 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, // void GEOM_Gen_i::Save(const char *IORSComponent, const char *aUrlOfFile) // { -// TCollection_ExtendedString path(strdup(aUrlOfFile)); +// TCollection_ExtendedString path((char*)aUrlOfFile); // TCollection_ExtendedString pathWithExt = path + TCollection_ExtendedString(".sgd"); // myOCAFApp->SaveAs(myCurrentOCAFDoc,pathWithExt); // } @@ -479,14 +560,14 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, // void GEOM_Gen_i::Load(const char *IORSComponent, const char *aUrlOfFile) // { -// TCollection_ExtendedString path(strdup(aUrlOfFile)); +// TCollection_ExtendedString path((char*)aUrlOfFile); // TCollection_ExtendedString pathWithExt = path + TCollection_ExtendedString(".sgd"); // myOCAFApp->Open(pathWithExt,myCurrentOCAFDoc); // SALOMEDS::SComponent_var SC = SALOMEDS::SComponent::_narrow(_orb->string_to_object(IORSComponent)); // SALOMEDS::Study_var Study = SC->GetStudy(); -// TCollection_AsciiString name( strdup(Study->Name()) ); +// TCollection_AsciiString name( Study->Name() ); // int StudyID = Study->StudyId(); // myStudyIDToDoc.Bind( StudyID, myCurrentOCAFDoc ); @@ -516,7 +597,7 @@ void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent) // Handle(TDocStd_Document) anEmptyDoc; // if (aDoc->Main().Root().FindAttribute(TDocStd_Owner::GetID(), anOwner)) { // anOwner->SetDocument(anEmptyDoc); -// cout<<"********** Nullify owner of document"<Close(aDoc); myStudyIDToDoc.UnBind(anID); // remove document from GEOM documents data map @@ -543,7 +624,7 @@ CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) { //============================================================================ SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) { // Declare a sequence of the byte to store the copied object - SALOMEDS::TMPFile_var aStreamFile; + SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile; // Try to get GEOM_Shape object by given SObject SALOMEDS::GenericAttribute_var anAttr; @@ -580,7 +661,7 @@ SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA:: CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) { // The Geometry component can paste only objects copied by Geometry component // and with the object type = 1 -// cout<<"********** GEOM_Gen_i::CanPaste ("<Register(g, strdup(name)); + name_service->Register(g, name); } @@ -682,7 +763,7 @@ TopoDS_Shape GEOM_Gen_i::GetTopoShape(GEOM::GEOM_Shape_ptr shape_ptr) TDF_Label lab ; Handle(TDF_Data) D = myCurrentOCAFDoc->GetData() ; - TDF_Tool::Label( D, strdup(shape_ptr->ShapeId()), lab, true ) ; + TDF_Tool::Label( D, shape_ptr->ShapeId(), lab, true ) ; Handle(TNaming_NamedShape) NamedShape ; bool res = lab.FindAttribute(TNaming_NamedShape::GetID(), NamedShape) ; @@ -712,8 +793,13 @@ const char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Shape_var shapeIOR) { // purpose : returns a 'GEOM::GEOM_Shape_var' from a string representing it //================================================================================= GEOM::GEOM_Shape_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) { - GEOM::GEOM_Shape_var shapeIOR = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(stringIOR)) ; - return shapeIOR ; + GEOM::GEOM_Shape_var shapeIOR; + if(strcmp(stringIOR,"") != 0){ + CORBA::Object_var anObject = _orb->string_to_object(stringIOR); + if(!CORBA::is_nil(anObject)) + shapeIOR = GEOM::GEOM_Shape::_narrow(anObject.in()) ; + } + return shapeIOR._retn() ; } @@ -727,7 +813,7 @@ const char * GEOM_Gen_i::InsertInLabel(TopoDS_Shape S, const char *mystr, Handle { GEOMDS_Commands GC(OCAFDoc->Main()); /* add attributs S and mystr in a new label */ - TDF_Label Lab = GC.AddShape (S, strdup(mystr)); + TDF_Label Lab = GC.AddShape (S, (char*)mystr); TCollection_AsciiString entry; TDF_Tool::Entry(Lab,entry); @@ -755,7 +841,7 @@ const char * GEOM_Gen_i::InsertInLabelDependentShape( TopoDS_Shape S, TDF_Tool::Label(OCAFDoc->GetData(), mainshape_ptr->ShapeId(), mainRefLab); /* add attributs : S, nameIor and ref to main */ - TDF_Label Lab = GC.AddDependentShape(S, strdup(nameIor), mainRefLab); + TDF_Label Lab = GC.AddDependentShape(S, (char*)nameIor, mainRefLab); TCollection_AsciiString entry; TDF_Tool::Entry(Lab, entry); @@ -835,7 +921,15 @@ void GEOM_Gen_i::InsertInLabelMoreArguments(TopoDS_Shape main_topo, //================================================================================= CORBA::Short GEOM_Gen_i::NbLabels() { - return TDF_Tool::NbLabels( myCurrentOCAFDoc->Main() ); + TDF_ChildIterator ChildIterator(myCurrentOCAFDoc->Main()); + unsigned int i = 1; + + while (ChildIterator.More()) { + i++; + ChildIterator.Next(); + } + return i; + // return TDF_Tool::NbLabels( myCurrentOCAFDoc->Main() ); } @@ -939,6 +1033,7 @@ int GEOM_Gen_i::SuppressFacesGlue( const TopoDS_Shape& S, TopoDS_Shape& aCompoundOfShells ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); BRepTools_Quilt Glue; aCompoundOfShells.Nullify() ; @@ -1027,6 +1122,7 @@ GEOM::GEOM_Shape::ListOfSubShapeID* GEOM_Gen_i::IndexOfFacesOfSubShell( const To throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID; ListOfID->length(0) ; if( subShell.IsNull() || subShell.ShapeType() != TopAbs_SHELL ) { @@ -1143,6 +1239,7 @@ GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SuppressFaces( GEOM::GEOM_Shape_pt const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Gen::ListOfGeomShapes_var listOfGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes; listOfGeomShapes->length(0) ; @@ -1291,6 +1388,7 @@ void GEOM_Gen_i::SuppressHoleSubRoutine( const TopoDS_Shape& mainShape, TopTools_MapOfShape& MSwireEndEdges ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); TopTools_MapOfShape MS ; TopTools_SequenceOfShape SU ; FreeEdgesFromMapOfFace(MSfaces, MS) ; /* MS = free edges of MSfaces */ @@ -1391,13 +1489,14 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHolesInFaceOrShell( GEOM::GEOM_Shape_pt const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdWires ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; if( ListIdWires.length() < 1 ) THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace : no holes selected", SALOME::BAD_PARAM); const TopoDS_Shape tds = GetTopoShape(shapeFaceShell) ; - if( tds.IsNull() || !BRepAlgoAPI::IsValid(tds) ) + if( tds.IsNull() || !IsValid(tds) ) THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace() : non valid main argument", SALOME::BAD_PARAM); /* Create a map of wires/holes to suppress */ @@ -1503,7 +1602,7 @@ bool GEOM_Gen_i::RebuildFaceRemovingHoles( const TopoDS_Face& aFace, { /* Get the outer wire of the face 'aFace' */ TopoDS_Wire outW = BRepTools::OuterWire( aFace ) ; - if( outW.IsNull() || !BRepAlgoAPI::IsValid(outW) ) + if( outW.IsNull() || !IsValid(outW) ) THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHolesInFace : bad outer wire of 'aFace'", SALOME::BAD_PARAM); /* Rebuild a face avoiding holes in the map 'mapHoles' */ @@ -1553,6 +1652,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHole( GEOM::GEOM_Shape_ptr shape, const GEOM::GEOM_Shape::ListOfSubShapeID& ListIdEndFace ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Face aFace ; TopoDS_Wire aWire ; @@ -1563,7 +1663,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHole( GEOM::GEOM_Shape_ptr shape, /* Retrieve 'aShape' the initial main shape selection */ const TopoDS_Shape aShape = GetTopoShape(shape); - if( !BRepAlgoAPI::IsValid(aShape) ) + if( !IsValid(aShape) ) THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : non valid main shape", SALOME::BAD_PARAM); if( ListIdFace.length() != 1 || ListIdWire.length() != 1 ) @@ -1576,7 +1676,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHole( GEOM::GEOM_Shape_ptr shape, else { aFace = TopoDS::Face(tmp) ; } - if( !BRepAlgoAPI::IsValid(aFace) ) + if( !IsValid(aFace) ) THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : face shape not valid", SALOME::BAD_PARAM); /* Retrieve 'aWire' selection : Warning : index of wire refers to the face ! */ @@ -1587,12 +1687,12 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHole( GEOM::GEOM_Shape_ptr shape, else { aWire = TopoDS::Wire(aTmp) ; } - if( !BRepAlgoAPI::IsValid(aWire) ) + if( !IsValid(aWire) ) THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : bad wire" , SALOME::BAD_PARAM); /* Get the outer wire of aFace */ TopoDS_Wire outerW = BRepTools::OuterWire( aFace ) ; - if( outerW.IsNull() || !BRepAlgoAPI::IsValid(outerW) ) + if( outerW.IsNull() || !IsValid(outerW) ) THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : bad outer wire", SALOME::BAD_PARAM); /* Test bad user selection aWire */ @@ -1606,7 +1706,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHole( GEOM::GEOM_Shape_ptr shape, } else { TopoDS_Shape aTemp ; - if( !GetShapeFromIndex( aShape, TopAbs_FACE, ListIdEndFace[0], aTemp ) || tmp.IsNull() || !BRepAlgoAPI::IsValid(aTemp) ) + if( !GetShapeFromIndex( aShape, TopAbs_FACE, ListIdEndFace[0], aTemp ) || tmp.IsNull() || !IsValid(aTemp) ) THROW_SALOME_CORBA_EXCEPTION("in GEOM_Gen_i::SuppressHole() : non valid endFace", SALOME::BAD_PARAM); /* Test if 'endFace' as at least one hole */ @@ -1616,7 +1716,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SuppressHole( GEOM::GEOM_Shape_ptr shape, int nbWires = 0 ; for( fExp.Init(endFace, TopAbs_WIRE); fExp.More(); fExp.Next() ) { TopoDS_Wire W = TopoDS::Wire( fExp.Current() ) ; - if( !W.IsNull() && BRepAlgoAPI::IsValid(W) ) + if( !W.IsNull() && IsValid(W) ) nbWires++ ; } if(nbWires > 1) @@ -1767,7 +1867,7 @@ bool GEOM_Gen_i::BuildShellWithFaceCompound( const TopoDS_Compound Comp, int i = 0 ; for( ex.Init( Comp, TopAbs_FACE); ex.More(); ex.Next() ) { TopoDS_Face F = TopoDS::Face( ex.Current() ) ; - if( !BRepAlgoAPI::IsValid(F) ) { + if( !IsValid(F) ) { return false ; } B.AddShellFace( resultShell, F ) ; @@ -1798,7 +1898,7 @@ bool GEOM_Gen_i::FindCompareWireHoleOnFace( const TopoDS_Face& F, /* Get the outer wire of aFace */ TopoDS_Wire outerW = BRepTools::OuterWire(F) ; - if( outerW.IsNull() || !BRepAlgoAPI::IsValid(outerW) ) { + if( outerW.IsNull() || !IsValid(outerW) ) { return false ; } @@ -1842,6 +1942,7 @@ bool GEOM_Gen_i::BuildShapeHoleNotTraversing( const TopoDS_Shape& aShape, TopoDS_Shape& resultTds ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); BRep_Builder B; TopExp_Explorer exp ; TopoDS_Face newFace ; @@ -1900,6 +2001,7 @@ bool GEOM_Gen_i::BuildShapeHoleTraversing( const TopoDS_Shape& aShape, TopoDS_Shape& resultTds ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); BRep_Builder B; TopExp_Explorer exp ; TopoDS_Face newFace ; @@ -2039,6 +2141,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShape(GEOM::GEOM_Shape_ptr shape, const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); return SubShapesOne(shape, (TopAbs_ShapeEnum) ShapeType, ListOfID); } @@ -2052,6 +2155,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShapeSorted(GEOM::GEOM_Shape_ptr shape, const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); return SubShapesOne(shape, (TopAbs_ShapeEnum) ShapeType, ListOfID, Standard_True); } @@ -2066,6 +2170,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::SubShapesOne( GEOM::GEOM_Shape_ptr shape, const Standard_Boolean Sort) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape mainShape; TopoDS_Shape mainTopo = GetTopoShape(shape); @@ -2146,6 +2251,7 @@ GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapeAll(GEOM::GEOM_Shape_ptr s CORBA::Short ShapeType) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); return SubShapesAll(shape, (TopAbs_ShapeEnum) ShapeType); } @@ -2158,6 +2264,7 @@ GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapeAllSorted(GEOM::GEOM_Shape CORBA::Short ShapeType) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); return SubShapesAll(shape, (TopAbs_ShapeEnum) ShapeType, Standard_True); } @@ -2172,6 +2279,7 @@ GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapesAll(GEOM::GEOM_Shape_ptr throw (SALOME::SALOME_Exception) { /* List of sub shapes returned */ + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Gen::ListOfGeomShapes_var listOfGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes; listOfGeomShapes->length(0) ; @@ -2258,21 +2366,21 @@ GEOM::GEOM_Gen::ListOfGeomShapes* GEOM_Gen_i::SubShapesAll(GEOM::GEOM_Shape_ptr return listOfGeomShapes._retn() ; } - //================================================================================= // function : MakeBoolean() // purpose : Boolean operation according to the type 'operation' //================================================================================= GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeBoolean(GEOM::GEOM_Shape_ptr shape1, - GEOM::GEOM_Shape_ptr shape2, - CORBA::Long operation) + GEOM::GEOM_Shape_ptr shape2, + CORBA::Long operation) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape shape ; TopoDS_Shape aShape1 ; TopoDS_Shape aShape2 ; - + try { aShape1 = GetTopoShape(shape1) ; aShape2 = GetTopoShape(shape2) ; @@ -2305,7 +2413,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeBoolean(GEOM::GEOM_Shape_ptr shape1, } /* We test the validity of resulting shape */ - if( !BRepAlgoAPI::IsValid(shape) ) { + if( !IsValid(shape) ) { THROW_SALOME_CORBA_EXCEPTION("Boolean aborted : non valid shape result", SALOME::BAD_PARAM); } @@ -2344,6 +2452,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFuse(GEOM::GEOM_Shape_ptr shape1, GEOM::GEOM_Shape_ptr shape2) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape aShape1 = GetTopoShape(shape1) ; TopoDS_Shape aShape2 = GetTopoShape(shape2) ; @@ -2359,7 +2468,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFuse(GEOM::GEOM_Shape_ptr shape1, } /* We test the validity of resulting shape */ - if( !BRepAlgoAPI::IsValid(shape) ) { + if( !IsValid(shape) ) { THROW_SALOME_CORBA_EXCEPTION("Fuse aborted : non valid shape result", SALOME::BAD_PARAM); } @@ -2430,9 +2539,9 @@ GEOM::PointStruct GEOM_Gen_i::MakePointStruct(CORBA::Double x, GEOM::DirStruct GEOM_Gen_i::MakeDirection(const GEOM::PointStruct& p) { GEOM::DirStruct d ; - d.PS.x = p.x ; d.PS.y = p.y ; d.PS.z = p.z ; - return d ; - } + d.PS.x = p.x ; d.PS.y = p.y ; d.PS.z = p.z ; + return d ; +} //================================================================================= // function : MakeBox() @@ -2446,6 +2555,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeBox(CORBA::Double x1, CORBA::Double z2) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); gp_Pnt P1(x1,y1,z1); gp_Pnt P2(x2,y2,z2); GEOM::GEOM_Shape_var result ; @@ -2478,6 +2588,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCylinder(const GEOM::PointStruct& pstruct, CORBA::Double height) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape tds ; gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ; @@ -2500,8 +2611,6 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCylinder(const GEOM::PointStruct& pstruct, return result ; } - - //================================================================================ // function : MakeSphere() // purpose : Make a sphere topology @@ -2512,6 +2621,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSphere(CORBA::Double x1, CORBA::Double radius) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; try { @@ -2530,8 +2640,6 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSphere(CORBA::Double x1, return result; } - - //================================================================================ // function : MakeTorus() // purpose : Create a torus topology @@ -2542,6 +2650,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeTorus( const GEOM::PointStruct& pstruct, CORBA::Double minor_radius ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape tds ; gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ; @@ -2576,6 +2685,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCone(const GEOM::PointStruct& pstruct, CORBA::Double height) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape tds ; gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ; @@ -2614,6 +2724,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCone(const GEOM::PointStruct& pstruct, GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportIGES(const char* filename) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; //VRV: OCC 4.0 migration IGESControl_Reader aReader; @@ -2624,9 +2735,13 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportIGES(const char* filename) THROW_SALOME_CORBA_EXCEPTION("Error in reading import file", SALOME::BAD_PARAM); } MESSAGE("ImportIGES : all Geometry Transfer" << endl ) ; +#if OCC_VERSION_MAJOR >= 5 + aReader.ClearShapes(); + aReader.TransferRoots(); +#else aReader.Clear(); aReader.TransferRoots(false); - +#endif MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes() << endl ); TopoDS_Shape shape = aReader.OneShape(); @@ -2655,6 +2770,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportIGES(const char* filename) GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportSTEP(const char* filename) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; //VRV: OCC 4.0 migration STEPControl_Reader aReader; @@ -2730,6 +2846,7 @@ GEOM::GEOM_Shape_ptr const CORBA::Short Limit) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var aResult; TopoDS_Shape tds ; //MESSAGE ("In Partition"); @@ -2761,7 +2878,6 @@ throw (SALOME::SALOME_Exception) GEOM::GEOM_Shape_var aShape = GetIORFromString( ListTools[ind] ); TopoDS_Shape Shape = GetTopoShape(aShape); if(Shape.IsNull() ) { - //MESSAGE ( "In Partition a tool shape is null" ); THROW_SALOME_CORBA_EXCEPTION("In Partition a shape is null", SALOME::BAD_PARAM); } if ( !ShapesMap.Contains( Shape ) && ToolsMap.Add( Shape )) @@ -2796,7 +2912,9 @@ throw (SALOME::SALOME_Exception) PS.AddShape(Shape); } + //MESSAGE ( "Partition::Compute() " ); PS.Compute ((TopAbs_ShapeEnum) Limit); + //MESSAGE ( "Partition::Compute() - END" ); // suppress result outside of shapes in KInsideMap for (ind = 0; ind < ListKeepInside.length(); ind++) { @@ -2815,7 +2933,7 @@ throw (SALOME::SALOME_Exception) tds = PS.Shape(); - if( !BRepAlgoAPI::IsValid(tds) ) { + if( !IsValid(tds) ) { //MESSAGE ( "In Partition: non valid shape result" ); THROW_SALOME_CORBA_EXCEPTION("Partition aborted : non valid shape result", SALOME::BAD_PARAM); } @@ -2896,9 +3014,11 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFilling(GEOM::GEOM_Shape_ptr myShape, CORBA::Short maxdeg, CORBA::Double tol3d, CORBA::Double tol2d, - CORBA::Short nbiter) + CORBA::Short nbiter, + CORBA::Boolean theApprox) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Face tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -2921,6 +3041,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFilling(GEOM::GEOM_Shape_ptr myShape, THROW_SALOME_CORBA_EXCEPTION("Initial shape doesn't contain only edges !", SALOME::BAD_PARAM); } C = BRep_Tool::Curve(TopoDS::Edge(Scurrent), First, Last); + if (C.IsNull()) continue; C = new Geom_TrimmedCurve(C, First, Last); Section.AddCurve(C) ; i++ ; @@ -2933,7 +3054,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFilling(GEOM::GEOM_Shape_ptr myShape, Handle(GeomFill_Line) Line = new GeomFill_Line(i) ; GeomFill_AppSurf App(mindeg, maxdeg, tol3d, tol2d, nbiter) ; /* user parameters */ - App.Perform(Line, Section) ; + App.Perform(Line, Section, theApprox) ; if (!App.IsDone()) { THROW_SALOME_CORBA_EXCEPTION("Filling aborted : non valid shape result", SALOME::BAD_PARAM); @@ -2959,7 +3080,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFilling(GEOM::GEOM_Shape_ptr myShape, } /* We test the validity of resulting shape */ - if( !BRepAlgoAPI::IsValid(tds) ) { + if( !IsValid(tds) ) { THROW_SALOME_CORBA_EXCEPTION("Filling aborted : non valid shape result", SALOME::BAD_PARAM); } else { @@ -3095,6 +3216,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeGlueFaces(GEOM::GEOM_Shape_ptr myShape, // appliquer BRepTools_SameParameter au compshell // (rendre parametres 2D des edges identiques aux parametres 3D) + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -3233,6 +3355,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewing( const GEOM::GEOM_Gen::ListOfIOR& Li CORBA::Double precision ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; BRepOffsetAPI_Sewing aMethod ; @@ -3251,7 +3374,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewing( const GEOM::GEOM_Gen::ListOfIOR& Li aMethod.Perform() ; tds = aMethod.SewedShape() ; - if( !BRepAlgoAPI::IsValid(tds) ) { + if( !IsValid(tds) ) { THROW_SALOME_CORBA_EXCEPTION("Make Sewing aborted : non valid shape", SALOME::BAD_PARAM); } if( tds.IsNull() ) { @@ -3271,6 +3394,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewingShape( GEOM::GEOM_Shape_ptr aShape, CORBA::Double precision ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds, S ; BRepOffsetAPI_Sewing aMethod ; @@ -3290,7 +3414,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewingShape( GEOM::GEOM_Shape_ptr aShape, aMethod.Perform() ; tds = aMethod.SewedShape() ; - if( !BRepAlgoAPI::IsValid(tds) ) { + if( !IsValid(tds) ) { THROW_SALOME_CORBA_EXCEPTION("Make Sewing aborted : non valid shape", SALOME::BAD_PARAM); } } @@ -3314,6 +3438,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSewingShape( GEOM::GEOM_Shape_ptr aShape, GEOM::GEOM_Shape_ptr GEOM_Gen_i::OrientationChange(GEOM::GEOM_Shape_ptr aShape) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; BRep_Builder aBuilder; @@ -3390,7 +3515,7 @@ GEOM::GEOM_Gen::ListOfIOR* GEOM_Gen_i::GetReferencedObjects(GEOM::GEOM_Shape_ptr Handle(TDataStd_Name) Att; L.FindAttribute(TDataStd_Name::GetID(),Att); TCollection_AsciiString nameIOR (Att->Get()) ; - aList[i] = strdup( nameIOR.ToCString() ); + aList[i] = CORBA::string_dup( nameIOR.ToCString() ); i++; } @@ -3440,7 +3565,7 @@ GEOM::GEOM_Gen::ListOfIOR* GEOM_Gen_i::GetObjects(GEOM::GEOM_Shape_ptr shape) if (!Att->Get().IsEqual(TCollection_ExtendedString("Arguments")) ) { TCollection_AsciiString nameIOR (Att->Get()); - aList[i] = strdup( nameIOR.ToCString() ); + aList[i] = CORBA::string_dup( nameIOR.ToCString() ); i++; } ChildIterator1.Next(); @@ -3456,12 +3581,15 @@ GEOM::GEOM_Gen::ListOfIOR* GEOM_Gen_i::GetObjects(GEOM::GEOM_Shape_ptr shape) GEOM::GEOM_Shape_ptr GEOM_Gen_i::ImportBREP(const char* filename) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); TopoDS_Shape tds ; GEOM::GEOM_Shape_var result ; try { - BRep_Builder aBuilder; - BRepTools::Read(tds, strdup(filename), aBuilder) ; + BRep_Builder aBuilder; + char* aCopyfilename = strdup(filename); + BRepTools::Read(tds, aCopyfilename, aBuilder) ; + free(aCopyfilename); if (tds.IsNull()) { THROW_SALOME_CORBA_EXCEPTION("Import BRep aborted", SALOME::BAD_PARAM); } @@ -3486,6 +3614,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePlane(const GEOM::PointStruct& pstruct, CORBA::Double trimsize) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; @@ -3519,13 +3648,14 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeVertex(CORBA::Double x, CORBA::Double z) throw (SALOME::SALOME_Exception) { - + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; gp_Pnt P(x,y,z); TopoDS_Shape tds = BRepBuilderAPI_MakeVertex(P).Shape(); if (tds.IsNull()) { THROW_SALOME_CORBA_EXCEPTION("Make Vertex/Point aborted", SALOME::BAD_PARAM); } + tds.Infinite(true); result = CreateObject(tds) ; const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ; result->ShapeId(entry); @@ -3541,6 +3671,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFace( GEOM::GEOM_Shape_ptr wire, CORBA::Boolean wantplanarface ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape aShape; TopoDS_Shape tds; @@ -3567,6 +3698,170 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFace( GEOM::GEOM_Shape_ptr wire, } +//================================================================================= +// function : MakeFaces() +// purpose : +//================================================================================= +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFaces(const GEOM::GEOM_Gen::ListOfIOR& ListShapes, + CORBA::Boolean wantplanarface) + throw (SALOME::SALOME_Exception) +{ + GEOM::GEOM_Shape_var result; + + try { + GEOM::GEOM_Shape_var aShape = GetIORFromString(ListShapes[0]); + TopoDS_Shape Shape = GetTopoShape(aShape); + if(Shape.IsNull() || Shape.ShapeType() != TopAbs_WIRE) { + THROW_SALOME_CORBA_EXCEPTION("Shell aborted : null shape during operation", SALOME::BAD_PARAM); + } + TopoDS_Wire W = TopoDS::Wire(Shape); + TopoDS_Shape FFace = BRepBuilderAPI_MakeFace(W, wantplanarface).Shape(); + if(!FFace.IsNull()) { + if(ListShapes.length() == 1) { + result = CreateObject(FFace); + InsertInLabelMoreArguments(FFace, result, ListShapes, myCurrentOCAFDoc); + } + else if(ListShapes.length() >= 2) { + TopoDS_Compound C; + BRep_Builder aBuilder; + aBuilder.MakeCompound(C); + BRepAlgo_FaceRestrictor FR; + + TopAbs_Orientation OriF = FFace.Orientation(); + TopoDS_Shape aLocalS = FFace.Oriented(TopAbs_FORWARD); + FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True); + + for(unsigned int i = 0; i < ListShapes.length(); i++) { + GEOM::GEOM_Shape_var aShape = GetIORFromString(ListShapes[i]); + TopoDS_Shape Shape = GetTopoShape(aShape); + if(Shape.IsNull()) { + THROW_SALOME_CORBA_EXCEPTION("Shell aborted : null shape during operation", SALOME::BAD_PARAM); + } + FR.Add(TopoDS::Wire(Shape)); + } + + FR.Perform(); + + if(FR.IsDone()) { + int k = 0; + TopoDS_Shape aFace; + for(; FR.More(); FR.Next()) { + aFace = FR.Current().Oriented(OriF); + aBuilder.Add(C, aFace); + k++; + } + if(k == 1) { + result = CreateObject(aFace); + InsertInLabelMoreArguments(aFace, result, ListShapes, myCurrentOCAFDoc); + } + else { + result = CreateObject(C); + InsertInLabelMoreArguments(C, result, ListShapes, myCurrentOCAFDoc); + } + } + } + } + else { + THROW_SALOME_CORBA_EXCEPTION("Null result in GEOM_Gen_i::MakeFace", SALOME::BAD_PARAM); + } + } + catch (Standard_Failure) { + THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeFace", SALOME::BAD_PARAM); + } + return result; +} + + +//================================================================================= +// function : MakeShell() +// purpose : Make a compound from a list containing one or more shapes +//================================================================================= +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeShell( const GEOM::GEOM_Gen::ListOfIOR& ListShapes ) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + GEOM::GEOM_Shape_var result ; + BRepTools_Quilt Glue; + TopoDS_Shape C; + + for ( unsigned int i = 0; i < ListShapes.length(); i++) { + GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[i] ); + TopoDS_Shape Shape = GetTopoShape(aShape) ; + if( Shape.IsNull() ) { + THROW_SALOME_CORBA_EXCEPTION("Shell aborted : null shape during operation", SALOME::BAD_PARAM); + } + Glue.Add(Shape) ; + } + + TopExp_Explorer exp(Glue.Shells(), TopAbs_SHELL); + Standard_Integer ish = 0; + for (; exp.More(); exp.Next()) { + C = exp.Current(); + ish++; + } + + if (ish != 1) + C = Glue.Shells(); + + if ( C.IsNull() ) { + THROW_SALOME_CORBA_EXCEPTION("Null result : Shell operation aborted", SALOME::BAD_PARAM); + } + else { + result = CreateObject(C) ; + InsertInLabelMoreArguments(C, result, ListShapes, myCurrentOCAFDoc) ; + } + return result; +} + + +//================================================================================= +// function : MakeSolid() +// purpose : Make a compound from a list containing one or more shapes +//================================================================================= +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSolid( const GEOM::GEOM_Gen::ListOfIOR& ListShapes ) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + GEOM::GEOM_Shape_var result ; + Standard_Integer ish = 0; + TopoDS_Compound Res; + TopoDS_Solid Sol; + BRep_Builder B; + TopoDS_Shape Shape; + + B.MakeCompound(Res); + + for ( unsigned int i = 0; i < ListShapes.length(); i++) { + GEOM::GEOM_Shape_var aShape = GetIORFromString( ListShapes[i] ); + TopoDS_Shape Sh = GetTopoShape(aShape) ; + if( Sh.IsNull() ) { + THROW_SALOME_CORBA_EXCEPTION("Solid aborted : null shape during operation", SALOME::BAD_PARAM); + } + B.MakeSolid(Sol); + B.Add(Sol,Sh); + BRepClass3d_SolidClassifier SC(Sol); + SC.PerformInfinitePoint(Precision::Confusion()); + if (SC.State() == TopAbs_IN) { + B.MakeSolid(Sol); + B.Add(Sol,Sh.Reversed()); + } + B.Add(Res,Sol); + ish++; + } + if (ish == 1) { Shape = Sol;} + else { Shape = Res;} + + if ( Shape.IsNull() ) { + THROW_SALOME_CORBA_EXCEPTION("Null result : Solid operation aborted", SALOME::BAD_PARAM); + } + else { + result = CreateObject(Shape) ; + InsertInLabelMoreArguments(Shape, result, ListShapes, myCurrentOCAFDoc) ; + } + return result; +} + + //================================================================================ // function : MakeLine // purpose : Make a Line topology @@ -3575,6 +3870,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeLine(const GEOM::PointStruct& pstruct, const GEOM::DirStruct& dstruct) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; gp_Pnt P1(pstruct.x, pstruct.y, pstruct.z); gp_Pnt P2(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ; @@ -3591,6 +3887,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeLine(const GEOM::PointStruct& pstruct, THROW_SALOME_CORBA_EXCEPTION("Make Line aborted : null shape", SALOME::BAD_PARAM); } else { + tds.Infinite(true); result = CreateObject(tds) ; const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ; result->ShapeId(entry); @@ -3607,6 +3904,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeVector(const GEOM::PointStruct& pstruct1, const GEOM::PointStruct& pstruct2) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; @@ -3640,6 +3938,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCircle(const GEOM::PointStruct& pstruct, CORBA::Double radius) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape tds ; @@ -3663,6 +3962,42 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCircle(const GEOM::PointStruct& pstruct, return result ; } +//================================================================================ +// function : MakeEllipse() +// purpose : +//================================================================================ +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeEllipse( const GEOM::PointStruct& pstruct, + const GEOM::DirStruct& dstruct, + CORBA::Double radius_major, + CORBA::Double radius_minor ) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + GEOM::GEOM_Shape_var result; + TopoDS_Shape tds ; + + try { + gp_Pnt p(pstruct.x, pstruct.y, pstruct.z) ; + gp_Dir d(dstruct.PS.x, dstruct.PS.y, dstruct.PS.z) ; + + const gp_Ax2 axis(p, d) ; + gp_Elips anEllipse( axis, radius_major, radius_minor ) ; + BRepBuilderAPI_MakeEdge MakeEdge( anEllipse ); + tds = MakeEdge.Edge(); + + } + catch(Standard_Failure) { + THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeEllipse", SALOME::BAD_PARAM); + } + if (tds.IsNull()) { + THROW_SALOME_CORBA_EXCEPTION("Make Ellipse aborted", SALOME::BAD_PARAM); + } + result = CreateObject(tds); + const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ; + result->ShapeId(entry); + return result ; +} + //================================================================================ // function : MakeArc() // purpose : make an arc of circle from pInit to pEnd and passing on pCircle @@ -3672,6 +4007,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeArc(const GEOM::PointStruct& pInit, const GEOM::PointStruct& pEnd) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; try { gp_Pnt pI(pInit.x, pInit.y, pInit.z) ; @@ -3699,8 +4035,118 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeArc(const GEOM::PointStruct& pInit, return result ; } +//================================================================================= +// function : MakeSketcher() +// purpose : Make a wire from a list containing many points +//================================================================================= +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeSketcher( const char *Cmd ) + throw (SALOME::SALOME_Exception) +{ + GEOM::GEOM_Shape_var result ; + TopoDS_Shape tds ; + try { + Sketcher_Profile aProfile (Cmd); + if(aProfile.IsDone()) + tds = aProfile.GetShape(); + } + catch(Standard_Failure) { + THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeSketcher", SALOME::BAD_PARAM); + } + + if (tds.IsNull()) { + THROW_SALOME_CORBA_EXCEPTION("MakeSketcher aborted : null shape", SALOME::BAD_PARAM); + } + else { + result = CreateObject(tds); + const char *entry = InsertInLabel(tds, result->Name(), myCurrentOCAFDoc) ; + result->ShapeId(entry) ; + } + return result; +} + +//================================================================================= +// function : MakeBezier() +// purpose : Make a wire from a list containing many points +//================================================================================= +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeBezier( const GEOM::GEOM_Gen::ListOfIOR& ListShapes ) + throw (SALOME::SALOME_Exception) +{ + GEOM::GEOM_Shape_var result; + TopoDS_Shape tds, Shape; + TColgp_Array1OfPnt CurvePoints(1, ListShapes.length()); + + try { + for(unsigned int i = 0; i < ListShapes.length(); i++) { + GEOM::GEOM_Shape_var aShape = GetIORFromString(ListShapes[i]); + Shape = GetTopoShape(aShape); + if(Shape.IsNull()) { + THROW_SALOME_CORBA_EXCEPTION("MakeBezier aborted : null shape during operation", SALOME::BAD_PARAM); + } + if(Shape.ShapeType() == TopAbs_VERTEX) { + const gp_Pnt& P = BRep_Tool::Pnt(TopoDS::Vertex(Shape)); + CurvePoints.SetValue(i + 1, P); + } + } + Handle(Geom_BezierCurve) GBC = new Geom_BezierCurve(CurvePoints); + tds = BRepBuilderAPI_MakeEdge(GBC); + } + catch(Standard_Failure) { + THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeBezier", SALOME::BAD_PARAM); + } + + if( tds.IsNull() ) { + THROW_SALOME_CORBA_EXCEPTION("Make Bezier operation aborted : null result", SALOME::BAD_PARAM); + } + else { + result = CreateObject(tds); + InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc); + } + return result; +} + + +//================================================================================= +// function : MakeInterpol() +// purpose : Make a wire from a list containing many points +//================================================================================= +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeInterpol( const GEOM::GEOM_Gen::ListOfIOR& ListShapes ) + throw (SALOME::SALOME_Exception) +{ + GEOM::GEOM_Shape_var result; + TopoDS_Shape tds, Shape; + TColgp_Array1OfPnt CurvePoints(1, ListShapes.length()); + + try { + for(unsigned int i = 0; i < ListShapes.length(); i++) { + GEOM::GEOM_Shape_var aShape = GetIORFromString(ListShapes[i]); + Shape = GetTopoShape(aShape); + if(Shape.IsNull()) { + THROW_SALOME_CORBA_EXCEPTION("MakeBSpline aborted : null shape during operation", SALOME::BAD_PARAM); + } + if(Shape.ShapeType() == TopAbs_VERTEX) { + const gp_Pnt& P = BRep_Tool::Pnt(TopoDS::Vertex(Shape)); + CurvePoints.SetValue(i + 1, P); + } + } + GeomAPI_PointsToBSpline GBC(CurvePoints); + tds = BRepBuilderAPI_MakeEdge(GBC); + } + catch(Standard_Failure) { + THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeBSpline", SALOME::BAD_PARAM); + } + + if( tds.IsNull() ) { + THROW_SALOME_CORBA_EXCEPTION("Make BSpline operation aborted : null result", SALOME::BAD_PARAM); + } + else { + result = CreateObject(tds) ; + InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ; + } + return result; +} + //================================================================================= // function : MakeTranslation() // purpose : Translate a 3D shape @@ -3711,6 +4157,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeTranslation( GEOM::GEOM_Shape_ptr myShape, CORBA::Double z) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape aShape = GetTopoShape(myShape) ; if( aShape.IsNull() ) { @@ -3741,6 +4188,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiTranslation1D( GEOM::GEOM_Shape_ptr my CORBA::Short nbtimes ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; @@ -3796,6 +4244,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiTranslation2D( GEOM::GEOM_Shape_ptr my CORBA::Short nbtimes2 ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; @@ -3853,6 +4302,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiRotation1D( GEOM::GEOM_Shape_ptr mySha CORBA::Short nbtimes) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -3906,6 +4356,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiRotation2D( GEOM::GEOM_Shape_ptr mySha CORBA::Short nbtimes2 ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -3990,6 +4441,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMultiRotation2D( GEOM::GEOM_Shape_ptr mySha GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCopy( GEOM::GEOM_Shape_ptr Shape) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(Shape) ; @@ -4015,6 +4467,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMirrorByPlane(GEOM::GEOM_Shape_ptr myShape, GEOM::GEOM_Shape_ptr shapePlane) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -4050,8 +4503,8 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMirrorByPlane(GEOM::GEOM_Shape_ptr myShape, /* Insert arguments in ocaf */ GEOM::GEOM_Gen::ListOfIOR_var ListShapes = new GEOM::GEOM_Gen::ListOfIOR; ListShapes->length(2); - ListShapes[0] = GetStringFromIOR(myShape) ; - ListShapes[1] = GetStringFromIOR(shapePlane) ; + ListShapes[0] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(myShape)) ; + ListShapes[1] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(shapePlane)) ; InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ; return result ; } @@ -4067,6 +4520,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeRotation( GEOM::GEOM_Shape_ptr myShape, CORBA::Double angle) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -4105,6 +4559,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeScaleTransform(GEOM::GEOM_Shape_ptr myShape CORBA::Double factor) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -4138,6 +4593,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeScaleTransform(GEOM::GEOM_Shape_ptr myShape GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCompound( const GEOM::GEOM_Gen::ListOfIOR& ListShapes ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Compound C; BRep_Builder aBuilder; @@ -4163,7 +4619,6 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCompound( const GEOM::GEOM_Gen::ListOfIOR& } - //================================================================================ // function : MakeEdge() // purpose : Make a linear edge with 2 points @@ -4172,6 +4627,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeEdge(const GEOM::PointStruct& pstruct1, const GEOM::PointStruct& pstruct2) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; @@ -4202,6 +4658,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeEdge(const GEOM::PointStruct& pstruct1, GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeWire( const GEOM::GEOM_Gen::ListOfIOR& ListShapes ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; BRepBuilderAPI_MakeWire MW ; TopoDS_Shape tds, Shape ; @@ -4236,7 +4693,6 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeWire( const GEOM::GEOM_Gen::ListOfIOR& List } - //================================================================================= // function : MakeRevolution() // purpose : @@ -4246,6 +4702,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeRevolution(GEOM::GEOM_Shape_ptr myShape, double angle) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -4279,6 +4736,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePipe( GEOM::GEOM_Shape_ptr pathShape, GEOM::GEOM_Shape_ptr baseShape ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Wire aWire ; @@ -4309,7 +4767,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePipe( GEOM::GEOM_Shape_ptr pathShape, THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePipe", SALOME::BAD_PARAM); } - if ( !BRepAlgoAPI::IsValid(tds) ) { + if ( !IsValid(tds) ) { THROW_SALOME_CORBA_EXCEPTION("MakePipe aborted : non valid shape result", SALOME::BAD_PARAM); } else { @@ -4318,8 +4776,8 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePipe( GEOM::GEOM_Shape_ptr pathShape, /* Insert arguments in ocaf */ GEOM::GEOM_Gen::ListOfIOR_var ListShapes = new GEOM::GEOM_Gen::ListOfIOR; ListShapes->length(2); - ListShapes[0] = GetStringFromIOR(pathShape) ; - ListShapes[1] = GetStringFromIOR(baseShape) ; + ListShapes[0] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(pathShape)) ; + ListShapes[1] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(baseShape)) ; InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ; } return result ; @@ -4335,6 +4793,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePrism( GEOM::GEOM_Shape_ptr myShape, const GEOM::PointStruct& P2 ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(myShape) ; @@ -4368,6 +4827,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePrism( GEOM::GEOM_Shape_ptr myShape, GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeCDG(GEOM::GEOM_Shape_ptr aShape) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape shape = GetTopoShape(aShape) ; @@ -4422,6 +4882,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::Archimede(GEOM::GEOM_Shape_ptr aShape, CORBA::Double aMeshingDeflection) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; double cste = -1; @@ -4495,6 +4956,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFillet( GEOM::GEOM_Shape_ptr shape, const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape tds ; @@ -4514,7 +4976,11 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFillet( GEOM::GEOM_Shape_ptr shape, fill.Add(E); } for (int i = 1;i<=fill.NbContours();i++) { +#if OCC_VERSION_MAJOR >= 5 + fill.SetRadius(radius,i,i); +#else fill.SetRadius(radius,i); +#endif } tds = fill.Shape(); @@ -4529,7 +4995,11 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFillet( GEOM::GEOM_Shape_ptr shape, } } for (int i = 1;i<=fill.NbContours();i++) { +#if OCC_VERSION_MAJOR >= 5 + fill.SetRadius(radius,i,i); +#else fill.SetRadius(radius,i); +#endif } tds = fill.Shape(); } @@ -4547,6 +5017,77 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFillet( GEOM::GEOM_Shape_ptr shape, return result ; } +//================================================================================ +// function : MakeFilletR1R2() +// purpose : Create a cylinder topology +//================================================================================ +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeFilletR1R2( GEOM::GEOM_Shape_ptr shape, + CORBA::Double radius1, + CORBA::Double radius2, + CORBA::Short ShapeType, + const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID ) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + GEOM::GEOM_Shape_var result; + TopoDS_Shape tds ; + + const TopoDS_Shape aShape = GetTopoShape(shape) ; + if( aShape.IsNull() ) { + THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM); + } + + BRepFilletAPI_MakeFillet fill(aShape); + + try { + /* case all */ + if(ListOfID.length() == 0) { + TopExp_Explorer Exp ( aShape, TopAbs_EDGE ); + for (Exp; Exp.More(); Exp.Next()) { + TopoDS_Edge E =TopoDS::Edge(Exp.Current()); + fill.Add(E); + } + for (int i = 1;i<=fill.NbContours();i++) { +#if OCC_VERSION_MAJOR >= 5 + fill.SetRadius(radius1,radius2,i,i); +#else + fill.SetRadius(radius1,radius2,i); +#endif + } + tds = fill.Shape(); + + } else { + + /* case selection */ + for ( unsigned int ind = 0; ind < ListOfID.length(); ind++ ) { + TopoDS_Shape ss ; + if( GetShapeFromIndex( aShape, (TopAbs_ShapeEnum)ShapeType, ListOfID[ind], ss ) ) { + TopoDS_Edge E = TopoDS::Edge(ss) ; + fill.Add( E ); + } + } + for (int i = 1;i<=fill.NbContours();i++) { +#if OCC_VERSION_MAJOR >= 5 + fill.SetRadius(radius1,radius2,i,i); +#else + fill.SetRadius(radius1,radius2,i); +#endif + } + tds = fill.Shape(); + } + } + catch(Standard_Failure) { + THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeFilletR1R2", SALOME::BAD_PARAM); + } + + if (tds.IsNull()) { + THROW_SALOME_CORBA_EXCEPTION("Make Fillet aborted", SALOME::BAD_PARAM); + } + result = CreateObject(tds); + InsertInLabelOneArgument(aShape, shape, tds, result, myCurrentOCAFDoc) ; + + return result ; +} //================================================================================ // function : MakeChamfer @@ -4559,6 +5100,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeChamfer( GEOM::GEOM_Shape_ptr shape, const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID ) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result; TopoDS_Shape tds ; @@ -4610,6 +5152,68 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeChamfer( GEOM::GEOM_Shape_ptr shape, return result ; } +//================================================================================ +// function : MakeChamferAD +// purpose : Create a Chamfer topology by Lenght & Angle +//================================================================================ +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeChamferAD( GEOM::GEOM_Shape_ptr shape, + CORBA::Double d, + CORBA::Double angle, + CORBA::Short ShapeType, + const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID ) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + GEOM::GEOM_Shape_var result; + TopoDS_Shape tds ; + + const TopoDS_Shape aShape = GetTopoShape(shape) ; + if( aShape.IsNull() ) { + THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM); + } + + BRepFilletAPI_MakeChamfer MC(aShape); + + try { + /* case all */ + TopTools_IndexedDataMapOfShapeListOfShape M; + TopExp::MapShapesAndAncestors(aShape,TopAbs_EDGE,TopAbs_FACE,M); + if(ListOfID.length() == 0) { + for (int i = 1;i<=M.Extent();i++) { + TopoDS_Edge E = TopoDS::Edge(M.FindKey(i)); + TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First()); + if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E)) + MC.AddDA(d,angle,E,F); + } + tds = MC.Shape(); + + } else { + + /* case selection */ + for ( unsigned int ind = 0; ind < ListOfID.length(); ind++ ) { + TopoDS_Shape ss ; + if( GetShapeFromIndex( aShape, (TopAbs_ShapeEnum)ShapeType, ListOfID[ind], ss ) ) { + TopoDS_Edge E = TopoDS::Edge( ss ) ; + TopoDS_Face F = TopoDS::Face(M.FindFromKey(E).First()); + if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E)) + MC.AddDA(d,angle,E,F); + } + } + tds = MC.Shape(); + } + } + catch(Standard_Failure) { + THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakeChamferAD", SALOME::BAD_PARAM); + } + + if (tds.IsNull()) { + THROW_SALOME_CORBA_EXCEPTION("Make ChamferAD aborted", SALOME::BAD_PARAM); + } + result = CreateObject(tds); + InsertInLabelOneArgument(aShape, shape, tds, result, myCurrentOCAFDoc) ; + return result ; +} + //================================================================================= // function : CheckShape() // purpose : @@ -4617,6 +5221,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeChamfer( GEOM::GEOM_Shape_ptr shape, CORBA::Boolean GEOM_Gen_i::CheckShape(GEOM::GEOM_Shape_ptr shape) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); TopoDS_Shape S = GetTopoShape(shape) ; if( S.IsNull() ) { THROW_SALOME_CORBA_EXCEPTION("Shape is null", SALOME::BAD_PARAM); @@ -4637,6 +5242,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePlacedBox(CORBA::Double x1, CORBA::Double CORBA::Double delta1, CORBA::Double delta2, CORBA::Double delta3) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; @@ -4676,6 +5282,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePanel(GEOM::GEOM_Shape_ptr shape, CORBA::Double delta) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); GEOM::GEOM_Shape_var result ; TopoDS_Shape tds ; TopoDS_Shape aShape = GetTopoShape(shape) ; @@ -4723,10 +5330,10 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePanel(GEOM::GEOM_Shape_ptr shape, GEOM::GEOM_Gen::ListOfIOR_var aList = new GEOM::GEOM_Gen::ListOfIOR; aList->length(4); - aList[0]=strdup(Edge1->Name()); - aList[1]=strdup(Edge2->Name()); - aList[2]=strdup(Edge3->Name()); - aList[3]=strdup(Edge4->Name()); + aList[0]=CORBA::string_dup(Edge1->Name()); + aList[1]=CORBA::string_dup(Edge2->Name()); + aList[2]=CORBA::string_dup(Edge3->Name()); + aList[3]=CORBA::string_dup(Edge4->Name()); GEOM::GEOM_Shape_ptr aWire = MakeWire( aList ); GEOM::GEOM_Shape_ptr aFace = MakeFace( aWire, true ) ; @@ -4752,6 +5359,7 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePanel(GEOM::GEOM_Shape_ptr shape, void GEOM_Gen_i::ExportIGES(const char* filename,GEOM::GEOM_Shape_ptr theShape) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); if (theShape->_is_nil()) { THROW_SALOME_CORBA_EXCEPTION("Export IGES aborted", SALOME::BAD_PARAM); @@ -4784,6 +5392,7 @@ void GEOM_Gen_i::ExportIGES(const char* filename,GEOM::GEOM_Shape_ptr theShape) void GEOM_Gen_i::ExportBREP(const char* filename,GEOM::GEOM_Shape_ptr theShape) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); if (theShape->_is_nil()) { THROW_SALOME_CORBA_EXCEPTION("Export BRep aborted", SALOME::BAD_PARAM); @@ -4808,6 +5417,7 @@ void GEOM_Gen_i::ExportBREP(const char* filename,GEOM::GEOM_Shape_ptr theShape) void GEOM_Gen_i::ExportSTEP(const char* filename,GEOM::GEOM_Shape_ptr theShape) throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SALOME_SalomeException); if (theShape->_is_nil()) { THROW_SALOME_CORBA_EXCEPTION("Export STEP aborted", SALOME::BAD_PARAM); @@ -4843,17 +5453,14 @@ void GEOM_Gen_i::ExportSTEP(const char* filename,GEOM::GEOM_Shape_ptr theShape) //===================================================================================== extern "C" { - PortableServer::ObjectId * GeometryEngine_factory(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char * interfaceName) + PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, + const char * interfaceName) { -MESSAGE("mygeom") GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName); -MESSAGE("mygeom") myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example -MESSAGE("mygeom") return myGEOM_Gen_i->getId() ; } }