//================================================================ // Function : Convert_Presentation::drawSurfaceAndItsBSpline // Purpose : //================================================================ void Convert_Presentation::drawSurfaceAndItsBSpline(Handle_Geom_Surface theSurface, const Standard_CString theName, TCollection_AsciiString& theText) { TCollection_AsciiString aTitle ("Converting "); aTitle += theName; aTitle += " to BSpline surface"; theText += EOL " Handle_Geom_BSplineSurface aBSplineSurface = " EOL " GeomConvert::SurfaceToBSplineSurface(aSurface);" EOL; setResultTitle (aTitle.ToCString()); setResultText (theText.ToCString()); drawSurface (theSurface, SurfaceColor); if (WAIT_A_LITTLE) return; Handle_Geom_BSplineSurface aBSplineSurface = GeomConvert::SurfaceToBSplineSurface(theSurface); _ASSERTE(!aBSplineSurface.IsNull()); drawSurface (aBSplineSurface, BSplineSurfaceColor); }
SALOME_WNT_EXPORT int ExportSTEP( const TopoDS_Shape& theShape, const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName) { MESSAGE("Export STEP into file " << theFileName.ToCString()); try { IFSelect_ReturnStatus status ; //VRV: OCC 4.0 migration STEPControl_Writer aWriter; //VSR: 16/09/09: Convert to METERS Interface_Static::SetCVal("xstep.cascade.unit","M"); Interface_Static::SetIVal("write.step.nonmanifold", 1); //JFA: PAL6162 status = aWriter.Transfer( theShape, STEPControl_ManifoldSolidBrep ); status = aWriter.Transfer( theShape, STEPControl_AsIs ); //VRV: OCC 4.0 migration if ( status == IFSelect_RetDone ) status = aWriter.Write( theFileName.ToCString() ) ; // Return previous locale if ( status == IFSelect_RetDone ) return 1; } catch(Standard_Failure) { Standard_Failure::Raise("Could not export in STEP format"); } return 0; }
////////////////////////////////////////////////////////////////////// // Sample functions ////////////////////////////////////////////////////////////////////// //================================================================ // Function : TexturesExt_Presentation::Texturize // display an AIS_TexturedShape based on a given shape with texture with given filename // filename can also be an integer value ("2", "5", etc.), in this case // a predefined texture from Graphic3d_NameOfTexture2D with number = this value // is loaded. //================================================================ Handle_AIS_TexturedShape TexturesExt_Presentation::Texturize(const TopoDS_Shape& aShape, TCollection_AsciiString aTFileName, Standard_Real toScaleU, Standard_Real toScaleV, Standard_Real toRepeatU, Standard_Real toRepeatV, Standard_Real originU, Standard_Real originV) { // create a textured presentation object for aShape Handle_AIS_TexturedShape aTShape = new AIS_TexturedShape(aShape); TCollection_AsciiString TFileName; // load texture from file if it is not an integer value // integer value indicates a number of texture in predefined TexturesExt enumeration CString initfile(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir()); initfile += "\\Data\\"; if (!aTFileName.IsIntegerValue()) { initfile += aTFileName.ToCString(); } aTShape->SetTextureFileName((Standard_CString)(LPCTSTR)initfile); // do other initialization of AIS_TexturedShape aTShape->SetTextureMapOn(); aTShape->SetTextureScale(Standard_True, toScaleU, toScaleV); aTShape->SetTextureRepeat(Standard_True, toRepeatU, toRepeatV); aTShape->SetTextureOrigin(Standard_True, originU, originV); aTShape->SetDisplayMode(3); // mode 3 is "textured" mode return aTShape; }
ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (const TCollection_AsciiString& theNameResource, const TCollection_AsciiString& thePrefix ) : myOperations(theNameResource.ToCString(),thePrefix.ToCString()) { //myResource = new Resource_Manager(theNameResource); myPrefix = thePrefix; mySaveHistoryMode = Standard_False; myLevel = TopAbs_FACE; myDone = Standard_False; }
// write geometry ////////////////// void writeFile( TCollection_AsciiString outFileName, Handle_TopTools_HSequenceOfShape shapes){ //get writer plugin TCollection_AsciiString fileExtension = outFileName; fileExtension = fileExtension.Split(fileExtension.SearchFromEnd(".")-1); McCadEXPlug_PluginManager* pluginManager = McCadEXPlug_PluginManager::Instance(); McCadEXPlug_ExchangePlugin* writerPlugin = pluginManager->GetPlugin(fileExtension); // write file writerPlugin->SetFilename(outFileName); writerPlugin->Export(shapes); }
SALOME_WNT_EXPORT int ExportBREP( const TopoDS_Shape& theShape, const TCollection_AsciiString& theFileName) { MESSAGE("Export BREP into file " << theFileName.ToCString()); if ( !BRepTools::Write( theShape, theFileName.ToCString() ) ) return 0; return 1; }
// read file, return geometry /////////////////////////////// Handle_TopTools_HSequenceOfShape readFile( TCollection_AsciiString fileName){ // get reader plugin TCollection_AsciiString fileExtension = fileName; fileExtension = fileExtension.Split(fileExtension.SearchFromEnd(".")-1); McCadEXPlug_PluginManager* pluginManager = McCadEXPlug_PluginManager::Instance(); McCadEXPlug_ExchangePlugin* readerPlugin = pluginManager->GetPlugin(fileExtension); // read file readerPlugin->SetFilename(fileName); Handle_TopTools_HSequenceOfShape shapes = new TopTools_HSequenceOfShape; shapes = readerPlugin->Import(); return shapes; }
void ShHealOper_ShapeProcess::SetOperators(const TColStd_SequenceOfAsciiString& theSeqOperators) { TCollection_AsciiString anameParam(myPrefix); anameParam += "."; anameParam += "exec.op"; TCollection_AsciiString aseq; Standard_Integer i =1; for( ; i <= theSeqOperators.Length(); i++) { aseq += theSeqOperators.Value(i); aseq += " "; } myOperations.Context()->ResourceManager()->SetResource(anameParam.ToCString(),aseq.ToCString()); }
//================================================================ // Function : TexturesExt_Presentation::loadShape // loads a shape from a given brep file from data dir into a given TopoDS_Shape object //================================================================ Standard_Boolean TexturesExt_Presentation::loadShape(TopoDS_Shape& aShape, TCollection_AsciiString aFileName) { // create a TopoDS_Shape -> read from a brep file CString initfile(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir()); initfile += "\\Data\\"; initfile += aFileName.ToCString(); TCollection_AsciiString Path((Standard_CString)(LPCTSTR)initfile); BRep_Builder aBld; //Standard_Boolean isRead = BRepTools::Read (aShape, aPath.ToCString(), aBld); //if (!isRead) // isRead = BRepTools::Read (aShape, bPath.ToCString(), aBld); Standard_Boolean isRead = BRepTools::Read (aShape, Path.ToCString(), aBld); if (!isRead) { Path += " was not found. The sample can not be shown."; getDocument()->UpdateResultMessageDlg("Textured Shape", Path.ToCString()); return Standard_False; } return Standard_True; }
Standard_Boolean ShHealOper_ShapeProcess::GetOperators(TColStd_SequenceOfAsciiString& theSeqOperators) { TCollection_AsciiString nameSeq(myPrefix); nameSeq +=".exec.op"; if(!myOperations.Context()->ResourceManager()->Find(nameSeq.ToCString())) return Standard_False; TCollection_AsciiString seqoper = myOperations.Context()->ResourceManager()->Value(nameSeq.ToCString()); Standard_Integer i; for ( i=1; ; i++ ) { TCollection_AsciiString anOper = seqoper.Token ( " \t,;", i ); if ( anOper.Length() <=0 ) break; theSeqOperators.Append(anOper); } return (theSeqOperators.Length()); }
void CViewer3dDoc::UpdateResultMessageDlg(CString Title, TCollection_AsciiString aMessage) { CString text(aMessage.ToCString()); myCResultDialog.SetText(text); myCResultDialog.SetTitle(Title); }
void ShHealOper_ShapeProcess::SetParameter(const TCollection_AsciiString& theNameParam, const TCollection_AsciiString& theVal) { TCollection_AsciiString anameParam(myPrefix); anameParam += "."; anameParam+= theNameParam; if(theVal.IsIntegerValue()) myOperations.Context()->ResourceManager()-> SetResource(anameParam.ToCString(),theVal.IntegerValue()); else if(theVal.IsRealValue()) myOperations.Context()->ResourceManager()-> SetResource(anameParam.ToCString(),theVal.RealValue()); else myOperations.Context()->ResourceManager()-> SetResource(anameParam.ToCString(),theVal.ToCString()); }
void OCC_3dDoc::PocessTextInDialog(char* aTitle, TCollection_AsciiString& aMessage) { // aMessage+= "-------------------------------- END ----------------------------------------\n"; CString text(aMessage.ToCString()); myCResultDialog.SetTitle(CString(aTitle)); myCResultDialog.SetText(text); SetTitle(CString(aTitle)); }
static void removeFile( const TCollection_AsciiString& fileName ) { try { OSD_File( fileName ).Remove(); } catch ( Standard_ProgramError ) { MESSAGE("Can't remove file: " << fileName.ToCString() << " ; file does not exist or permission denied"); } }
void OCC_3dDoc::AddTextInDialog(TCollection_AsciiString& aMessage) { CString TextToAdd(aMessage.ToCString()); CString CurrentText; myCResultDialog.GetText(CurrentText); CString Text; Text = TextToAdd + CurrentText; myCResultDialog.SetText(Text); }
STLEXPORT_EXPORT int Export(const TopoDS_Shape& theShape, const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName) { MESSAGE("Export STL into file " << theFileName.ToCString()); try { StlAPI_Writer aWriter; bool aIsASCIIMode; aIsASCIIMode = (theFormatName.IsEqual("STL_ASCII")) ? true : false; aWriter.ASCIIMode() = aIsASCIIMode; aWriter.Write(theShape, theFileName.ToCString()) ; return 1; } catch(Standard_Failure) { //THROW_SALOME_CORBA_EXCEPTION("Exception catched in STLExport", SALOME::BAD_PARAM); } return 0; }
SALOME_WNT_EXPORT int Export(const TopoDS_Shape& theShape, const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName) { MESSAGE("Export CSFDB into file " << theFileName.ToCString()); try { if ( theShape.IsNull() ) return 0; FSD_File f; Handle(ShapeSchema) s = new ShapeSchema; Handle(Storage_Data) d = new Storage_Data; d->ClearErrorStatus(); d->SetApplicationName("GEOM CSFDB PLUGIN"); d->SetApplicationVersion("3.2.6"); d->SetDataType("Shapes"); d->AddToUserInfo("Saved from GEOM CSFDB Plugin"); d->AddToComments("Based on GEOM 3.2.6 and Open CAS.CADE 6.2"); Storage_Error err = f.Open(theFileName, Storage_VSWrite); if ( err != Storage_VSOk ) return 0; PTColStd_TransientPersistentMap aMap; TCollection_AsciiString anObjectName("Object"); Handle(PTopoDS_HShape) aPShape = MgtBRep::Translate(theShape, aMap, MgtBRep_WithTriangle); d->AddRoot(anObjectName, aPShape); s->Write( f, d); f.Close(); if ( d->ErrorStatus() != Storage_VSOk ) return 0; return 1; } catch(Standard_Failure) { Standard_Failure::Raise("Could not export in CSFDB format"); } return 0; }
//================================================================ // Function : Convert_Presentation::drawCurveAndItsBSpline // Purpose : //================================================================ void Convert_Presentation::drawCurveAndItsBSpline(Handle_Geom_Curve theCurve, const Standard_CString theName, TCollection_AsciiString& theText) { TCollection_AsciiString aTitle ("Converting "); aTitle += theName; aTitle += " to BSpline curve"; theText += EOL " Handle_Geom_BSplineCurve aBSpline = " EOL " GeomConvert::CurveToBSplineCurve(aCurve);" EOL; setResultTitle (aTitle.ToCString()); setResultText (theText.ToCString()); drawCurve (theCurve, CurveColor); if (WAIT_A_LITTLE) return; Handle_Geom_BSplineCurve aBSpline = GeomConvert::CurveToBSplineCurve(theCurve); drawCurve (aBSpline, BSplineColor); }
SALOME_WNT_EXPORT TopoDS_Shape ImportBREP (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, TCollection_AsciiString& theError, const TDF_Label& theLabel) { MESSAGE("Import BREP from file " << theFileName); TopoDS_Shape aShape; BRep_Builder B; BRepTools::Read(aShape, theFileName.ToCString(), B); if (aShape.IsNull()) { theError = "BREP Import failed"; } return aShape; }
SALOME_WNT_EXPORT TopoDS_Shape ImportIGES (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, TCollection_AsciiString& theError, const TDF_Label& theShapeLabel) { IGESControl_Reader aReader; TopoDS_Shape aResShape; Interface_Static::SetCVal("xstep.cascade.unit","M"); try { IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); if (status == IFSelect_RetDone) { if( theFormatName == "IGES_UNIT" ) { Handle(IGESData_IGESModel) aModel = Handle(IGESData_IGESModel)::DownCast(aReader.Model()); gp_Pnt P(1.0,0.0,0.0); if(!aModel.IsNull()) { Handle(TCollection_HAsciiString) aUnitName = aModel->GlobalSection().UnitName(); //cout<<"aUnitName = "<<aUnitName->ToCString()<<endl; //cout<<"aUnitFlag = "<<aModel->GlobalSection().UnitFlag()<<endl; if( aUnitName->String()=="MM" ) { P = gp_Pnt(0.001,0.0,0.0); } else if( aUnitName->String()=="CM" ) { P = gp_Pnt(0.01,0.0,0.0); } } BRep_Builder B; TopoDS_Vertex V; B.MakeVertex(V,P,1.e-7); aResShape = V; return aResShape; } if( theFormatName == "IGES_SCALE" ) { //cout<<"need re-scale a model"<<endl; // set UnitFlag to 'meter' Handle(IGESData_IGESModel) aModel = Handle(IGESData_IGESModel)::DownCast(aReader.Model()); if(!aModel.IsNull()) { IGESData_GlobalSection aGS = aModel->GlobalSection(); aGS.SetUnitFlag(6); aModel->SetGlobalSection(aGS); } } MESSAGE("ImportIGES : all Geometry Transfer"); //OCC 5.1.2 porting // aReader.Clear(); // aReader.TransferRoots(false); aReader.ClearShapes(); aReader.TransferRoots(); MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes()); aResShape = aReader.OneShape(); // BEGIN: Store names of sub-shapes from file Handle(Interface_InterfaceModel) Model = aReader.WS()->Model(); Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader(); if (!TR.IsNull()) { Handle(Transfer_TransientProcess) TP = /*TransientProcess();*/TR->TransientProcess(); Standard_Integer nb = Model->NbEntities(); for (Standard_Integer i = 1; i <= nb; i++) { Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(Model->Value(i)); if (ent.IsNull() || ! ent->HasName()) continue; // find target shape Handle(Transfer_Binder) binder = TP->Find(ent); if (binder.IsNull()) continue; TopoDS_Shape S = TransferBRep::ShapeResult(binder); if (S.IsNull()) continue; // create label and set shape TDF_Label L; TDF_TagSource aTag; L = aTag.NewChild(theShapeLabel); TNaming_Builder tnBuild (L); tnBuild.Generated(S); // set a name TCollection_AsciiString string = ent->NameValue()->String(); string.LeftAdjust(); string.RightAdjust(); TCollection_ExtendedString str (string); TDataStd_Name::Set(L, str); } } // END: Store names } else { // switch (status) { // case IFSelect_RetVoid: // theError = "Nothing created or No data to process"; // break; // case IFSelect_RetError: // theError = "Error in command or input data"; // break; // case IFSelect_RetFail: // theError = "Execution was run, but has failed"; // break; // case IFSelect_RetStop: // theError = "Execution has been stopped. Quite possible, an exception was raised"; // break; // default: // break; // } theError = "Wrong format of the imported file. Can't import file."; aResShape.Nullify(); } } catch(Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); theError = aFail->GetMessageString(); aResShape.Nullify(); } return aResShape; }
{ getAISContext()->EraseAll(); if (myIndex >=0 && myIndex < myNbFuncs) (this->*SampleFuncs[myIndex])(); } //================================================================ // Function : Convert_Presentation::drawSurfaceAndItsBSpline // Purpose : //================================================================ void Convert_Presentation::drawSurfaceAndItsBSpline(Handle(Geom_Surface) theSurface, const Standard_CString theName, TCollection_AsciiString& theText) { TCollection_AsciiString aTitle ("Converting "); aTitle += theName; aTitle += " to BSpline surface"; theText += EOL " Handle(Geom_BSplineSurface) aBSplineSurface = " EOL " GeomConvert::SurfaceToBSplineSurface(aSurface);" EOL; setResultTitle (aTitle.ToCString()); setResultText (theText.ToCString()); drawSurface (theSurface, SurfaceColor); if (WAIT_A_LITTLE) return; Handle(Geom_BSplineSurface) aBSplineSurface = GeomConvert::SurfaceToBSplineSurface(theSurface);
SALOME_WNT_EXPORT int Export( const TopoDS_Shape& theShape, const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName) { MESSAGE("Export OBJ into file " << theFileName.ToCString()); std::ofstream fout(theFileName.ToCString()); Standard_Real Umin, Umax, Vmin, Vmax, dUmax, dVmax; TopExp_Explorer ExpFace; StdPrs_ToolShadedShape SST; //Triangulate BRepMesh::Mesh(theShape, DEFAULT_DEVIATION); Standard_Integer ShapeId = 1; Standard_Integer baseV = 0; Standard_Integer baseN = 0; Standard_Integer baseT = 0; for(ExpFace.Init(theShape, TopAbs_FACE); ExpFace.More(); ExpFace.Next()) { TopoDS_Face myFace = TopoDS::Face(ExpFace.Current()); TopLoc_Location aLocation; Handle(Poly_Triangulation) myT = BRep_Tool::Triangulation(myFace, aLocation); if (!myT.IsNull()) { Poly_Connect pc(myT); //write vertex buffer const TColgp_Array1OfPnt& Nodes = myT->Nodes(); for (int i = Nodes.Lower(); i <= Nodes.Upper(); i++) { gp_Pnt p = Nodes(i).Transformed(aLocation.Transformation()); fout << "v " << p.X() << " " << p.Y() << " " << p.Z() << std::endl; } fout << std::endl; //write normal buffer TColgp_Array1OfDir myNormal(Nodes.Lower(), Nodes.Upper()); SST.Normal(myFace, pc, myNormal); //myNormal.Length(); for (int i = myNormal.Lower(); i <= myNormal.Upper(); i++) { gp_Dir d = myNormal(i).Transformed(aLocation.Transformation()); fout << "vn " << d.X() << " " << d.Y() << " " << d.Z() << std::endl; } fout << std::endl; //write uvcoord buffer BRepTools::UVBounds(myFace,Umin, Umax, Vmin, Vmax); dUmax = (Umax - Umin); dVmax = (Vmax - Vmin); const TColgp_Array1OfPnt2d& UVNodes = myT->UVNodes(); for (int i = UVNodes.Lower(); i <= UVNodes.Upper(); i++) { gp_Pnt2d d = UVNodes(i); Standard_Real u = (-UOrigin+(URepeat*(d.X()-Umin))/dUmax)/ScaleU; Standard_Real v = (-VOrigin+(VRepeat*(d.Y()-Vmin))/dVmax)/ScaleV; fout << "vt " << u << " " << v << " 0" << std::endl; } fout << std::endl; //write triangle buffer if (Interface_Static::IVal("write.obj.groups")) fout << "g face_" << ShapeId++ << std::endl; Standard_Integer n1 , n2 , n3; const Poly_Array1OfTriangle& triangles = myT->Triangles(); for (int nt = 1; nt <= myT->NbTriangles(); nt++) { if (SST.Orientation(myFace) == TopAbs_REVERSED) triangles(nt).Get(n1,n3,n2); else triangles(nt).Get(n1,n2,n3); if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) ) { fout << "f " <<n1 + baseV<<"/"<<n1 + baseT<<"/"<<n1 + baseN<<" " <<n2 + baseV<<"/"<<n2 + baseT<<"/"<<n2 + baseN<<" " <<n3 + baseV<<"/"<<n3 + baseT<<"/"<<n3 + baseN<<" " <<std::endl; } } fout << std::endl; baseV += Nodes.Length(); baseN += myNormal.Length(); baseT += UVNodes.Length(); } } fout << std::flush; fout.close(); return 1; }
void COffsetDlg::SetOffsets(Standard_Real theFactor, Standard_Real theUnits) { Handle(AIS_InteractiveContext) aAISContext = myDoc->GetAISContext(); Handle(AIS_Shape) aOverlappedBox = myDoc->GetOverlappedBox(); Handle(AIS_Shape) aOverlappedCylinder = myDoc->GetOverlappedCylinder(); Handle(AIS_Shape) aOverlappedSphere = myDoc->GetOverlappedSphere(); Handle(AIS_Shape) aBox = myDoc->GetBox(); Handle(User_Cylinder) aCylinder = myDoc->GetCylinder(); Handle(AIS_Shape) aSphere = myDoc->GetSphere(); myDoc->SetDialogTitle("Set offsets"); TCollection_AsciiString Message; Standard_Boolean OneOrMoreCurrentIsDisplayed=false; for (aAISContext->InitCurrent();aAISContext->MoreCurrent ();aAISContext->NextCurrent ()) if (aAISContext->IsDisplayed(aAISContext->Current())) OneOrMoreCurrentIsDisplayed=true; if(OneOrMoreCurrentIsDisplayed){ if((aAISContext->IsCurrent(aOverlappedBox) || aAISContext->IsCurrent(aBox)) && aAISContext->IsDisplayed(aOverlappedBox)){ aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits); Message = "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; //myDoc -> AddTextInDialog(Message); } if((aAISContext->IsCurrent(aOverlappedCylinder) || aAISContext->IsCurrent(aCylinder)) && aAISContext->IsDisplayed(aOverlappedCylinder)){ aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits); Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; //myDoc -> AddTextInDialog(Message); } if((aAISContext->IsCurrent(aOverlappedSphere) || aAISContext->IsCurrent(aSphere)) && aAISContext->IsDisplayed(aOverlappedSphere)){ aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits); Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; //myDoc -> AddTextInDialog(Message); } } else{ if(aAISContext->IsDisplayed(aOverlappedBox)){ aOverlappedBox->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits); Message = Message + "Box2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; //myDoc -> AddTextInDialog(Message); } if(aAISContext->IsDisplayed(aOverlappedCylinder)){ aOverlappedCylinder->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits); Message = Message + "Cylinder2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; //myDoc -> AddTextInDialog(Message); } if(aAISContext->IsDisplayed(aOverlappedSphere)){ aOverlappedSphere->SetPolygonOffsets(Aspect_POM_Fill,theFactor,theUnits); Message = Message + "Sphere2 -> SetPolygonOffsets(Aspect_POM_Fill, Factor, Units);\n"; //myDoc -> AddTextInDialog(Message); } } CString aTextInDialog = myDoc -> GetDialogText(); if (strcmp(aTextInDialog, Message.ToCString())) myDoc -> UpdateResultMessageDlg("Set offsets", Message); aAISContext->UpdateCurrentViewer(); }
// MAIN ////////////////////// int main(int argc, char *argv[]) { // define messenger system McCadMessenger_Singleton *msgr = McCadMessenger_Singleton::Instance(); McCadMessenger_ObserverInterface* stdCoutObserver = new McCadMessenger_StdOut; msgr->Register(stdCoutObserver); // define plugin path char* pLibPath = getenv("MCCAD_LIBDIR"); OSD_Path pluginPath("empty"); if (pLibPath == NULL) { cout << "MCCAD_LIBDIR is not defined!!! " << endl; return 1; } else pluginPath = OSD_Path(pLibPath); // load plugins McCadEXPlug_PluginManager* pluginManager = McCadEXPlug_PluginManager::Instance(); pluginManager->LoadSharedLibrary(pluginPath); // handle input parameters TCollection_AsciiString Prog = argv[0]; if(argc > 4 ) { string arg3(argv[3]), arg4(argv[4]); if(arg3 == ">" || arg3 == ">>") { argc = 3; } else if(arg4 == ">" || arg4 == ">>") { argc = 4; } else { printUsage(Prog); exit(0); } } bool openFile = false; // handle input TCollection_AsciiString inName; if(argc > 1) //if (1) { TCollection_AsciiString inParameter; inParameter = argv[1]; if(argc > 2) inName = argv[2]; TCollection_AsciiString outputName; TCollection_AsciiString strMatName = ""; if (argc > 3) strMatName = argv[3]; if(inParameter.IsEqual("-h") || inParameter.IsEqual("--help")) { printUsage(); exit(0); } /* test code */ //inParameter = "-m"; TCollection_AsciiString config_file = "McCadConfig.txt"; //inName = "convertedTest.stp"; //strMatName = "material.xml"; /* test code */ // Expander if(inParameter.IsEqual("-e") || inParameter.IsEqual("--explode")) { cout << "\nMcCad_Exploder\n====================\n\n"; Handle_TopTools_HSequenceOfShape inputShapes = readFile( inName ); McCadIOHelper_Expander expander(inputShapes); Handle_TopTools_HSequenceOfShape expandedFiles = expander.GetExplodedShapes(); if(expandedFiles->Length() < 2){ TCollection_AsciiString message("Failed to expand file : "); message.AssignCat(inName); msgr->Message(message.ToCString()); exit(0); } TCollection_AsciiString tmpName(inName); TCollection_AsciiString fileFilter = tmpName.Split( tmpName.SearchFromEnd(".") -1 ); for(int i=1; i<=expandedFiles->Length(); i++){ TCollection_AsciiString outName(tmpName); outName.Prepend("ExOut"); outName.AssignCat("_"); outName.AssignCat(i); outName.AssignCat(fileFilter); Handle_TopTools_HSequenceOfShape singleShape = new TopTools_HSequenceOfShape; singleShape->Append(expandedFiles->Value(i)); writeFile(outName, singleShape); } } // Convertor else if(inParameter.IsEqual("-d") || inParameter.IsEqual("--decompose")) { cout << "\nMcCad_Decomposer\n====================\n\n"; // read file Handle_TopTools_HSequenceOfShape inputShapes = readFile( inName ); // decompose geometry McCadConvertTools_Convertor convertor(inputShapes); convertor.Convert(); if (argc == 4 && !outputName.IsEmpty()) convertor.SetFileName(outputName); if(!convertor.IsConverted()){ cout << "Conversion failed!!!\n"; return -1; } // export decomposed geometry to stp file TCollection_AsciiString exportName("converted"); exportName += inName; inName = exportName.Split(exportName.SearchFromEnd(".")); exportName += "stp"; writeFile( exportName, convertor.GetConvertedModel()); } // export decomposed geometry to stp file // Lei Lu 20150501 // TCollection_AsciiString exportName("converted"); // exportName += inName; // inName = exportName.Split(exportName.SearchFromEnd(".")); // exportName += "stp"; // writeFile( exportName, convertor.GetConvertedModel()); // } // Fuse else if(inParameter.IsEqual("-f") || inParameter.IsEqual("--fuse")) { cout << "\nMcCad_Fusioner\n====================\n\n"; McCadIOHelper_Merger myMerger(inName); if(argc == 4 && !outputName.IsEmpty()) myMerger.MergeToFile(outputName); else myMerger.Merge(); } // Surface check else if(inParameter.IsEqual("-s") || inParameter.IsEqual("--surface-check")) { cout << "\n McCad_SurfaceChecker\n====================\n\n"; if(argc < 3 || (argc == 4 && outputName.IsEmpty()) || argc > 4) { cout << "Output file name required\n\n"; exit(-1); } McCadCSGTool_SurfaceChecker surfCheck; surfCheck.readDirectory(inName, outputName); } // Void Generator else if(inParameter.IsEqual("-m") || inParameter.IsEqual("--mcnp") || inParameter.IsEqual("-t") || inParameter.IsEqual("--tripoli")|| inParameter.IsEqual("-g") || inParameter.IsEqual("--gdml")) { // read parameter file if (!McCadConvertConfig::ReadPrmt(config_file)) { return 0; } McCadInputModelData input_model; if (!input_model.LoadSTEPModel(inName)) { cout << "#Main Function: Read geometry data error! Please check the input file name!\n\n"; return 0; } // New void generation algorithm // Modified by Lei Lu 12/08/2012 ~ 18/12/2013 McCadVoidCellManager * pVoidCellManager = new McCadVoidCellManager(); Handle(TopTools_HSequenceOfShape) hInputShape = input_model.GetModelData(); pVoidCellManager->ReadGeomData( hInputShape ); pVoidCellManager->ReadMatData(strMatName); TCollection_AsciiString outName = inName; // Set the output file name outName.Split(outName.SearchFromEnd(".")-1); // Remove the file extension. if(inParameter.IsEqual("-t") || inParameter.IsEqual("--tripoli")) { pVoidCellManager->SetConvetor("TRIPOLI"); outName += "_TRIPOLI.txt"; } else if(inParameter.IsEqual("-m") || inParameter.IsEqual("--mcnp")) { pVoidCellManager->SetConvetor("MCNP"); outName += "_MCNP.txt"; } //qiu add to generate GDML input else if (inParameter.IsEqual("-g") || inParameter.IsEqual("--gdml")) { pVoidCellManager->SetConvetor("GDML"); outName += ".gdml"; } pVoidCellManager->SetOutFileName(outName); pVoidCellManager->Process(); // Process the conversion work delete pVoidCellManager; pVoidCellManager = NULL; } // open file for GUI else if(inParameter.Search(".stp") > 0 || inParameter.Search(".mcn") > 0 || inParameter.Search(".d") > 0 || inParameter.Search(".step") > 0 || inParameter.Search(".mcnp") > 0 || inParameter.Search(".tri") > 0 || inParameter.IsEqual(".") ) { openFile = true; inName = inParameter; } // print version else if(inParameter.IsEqual("-v") || inParameter.IsEqual("--version")) printVersion(); else { cout << "\nUnknown Parameter ... " << argv[1] << endl; printUsage(Prog); } if(!openFile) return 0; } // GUI ////////////////////////////////////// QApplication app(argc, argv); QSplashScreen* splash = new QSplashScreen(QPixmap(":images/splash.png"), Qt::WindowStaysOnTopHint); splash->show(); splash->showMessage(app.tr("Loading libraries ....."), Qt::AlignRight | Qt::AlignBottom); QMcCad_Application QMcWin; // loading plugins QMcWin.SetPluginPath(pluginPath); QMcWin.LoadPlugins(); Handle_TColStd_HSequenceOfAsciiString Formats = QMcWin.Formats(); for (int j=1; j<= Formats->Length(); j++) splash->showMessage(app.tr(Formats->Value(j).ToCString()), Qt::AlignRight|Qt::AlignBottom); QMcWin.show(); // delete splash if (splash) { splash->finish(&QMcWin); delete splash; } // open file imediately after window is loaded if(openFile) QMcWin.SetOpenFile(inName); // run Qt program return app.exec(); }
bool buildDistribution( const TCollection_AsciiString& f, const int conv, const double start, const double end, const int nbSeg, vector<double>& data, const double eps ) { FunctionExpr F( f.ToCString(), conv ); return buildDistribution( F, start, end, nbSeg, data, eps ); }
//======================================================================= // profile // command to build a profile //======================================================================= Sketcher_Profile::Sketcher_Profile(const char* aCmd) { enum {line, circle, point, none} move; Standard_Integer i = 1; Standard_Real x0, y0, x, y, dx, dy; x0 = y0 = x = y = dy = 0; dx = 1; Standard_Boolean first, stayfirst, face, close; first = Standard_True; stayfirst = face = close = Standard_False; Standard_Integer reversed = 0; Standard_Integer control_Tolerance = 0; TopoDS_Shape S; TopoDS_Vertex MP; BRepBuilderAPI_MakeWire MW; gp_Ax3 DummyHP(gp::XOY()); gp_Pln P(DummyHP); TopLoc_Location TheLocation; Handle(Geom_Surface) Surface; myOK = Standard_False; myError = 0; //TCollection_AsciiString aCommand(CORBA::string_dup(aCmd)); TCollection_AsciiString aCommand ((char*)aCmd); TCollection_AsciiString aToken = aCommand.Token(":", 1); int n = 0; // porting to WNT TColStd_Array1OfAsciiString aTab (0, aCommand.Length() - 1); if ( aCommand.Length() ) { while(aToken.Length() != 0) { if(aCommand.Token(":", n + 1).Length() > 0) aTab(n) = aCommand.Token(":", n + 1); aToken = aCommand.Token(":", ++n); } n = n - 1; } if ( aTab.Length() && aTab(0).Length() ) while(i < n) { Standard_Real length = 0, radius = 0, angle = 0; move = point; int n1 = 0; TColStd_Array1OfAsciiString a (0, aTab(0).Length()); aToken = aTab(i).Token(" ", 1); while (aToken.Length() != 0) { if (aTab(i).Token(" ", n1 + 1).Length() > 0) a(n1) = aTab(i).Token(" ", n1 + 1); aToken = aTab(i).Token(" ", ++n1); } n1 = n1 - 1; switch(a(0).Value(1)) { case 'F': { if (n1 != 3) goto badargs; if (!first) { MESSAGE("profile : The F instruction must precede all moves"); return; } x0 = x = a(1).RealValue(); y0 = y = a(2).RealValue(); stayfirst = Standard_True; break; } case 'O': { if (n1 != 4) goto badargs; P.SetLocation(gp_Pnt(a(1).RealValue(), a(2).RealValue(), a(3).RealValue())); stayfirst = Standard_True; break; } case 'P': { if (n1 != 7) goto badargs; gp_Vec vn(a(1).RealValue(), a(2).RealValue(), a(3).RealValue()); gp_Vec vx(a(4).RealValue(), a(5).RealValue(), a(6).RealValue()); if (vn.Magnitude() <= Precision::Confusion() || vx.Magnitude() <= Precision::Confusion()) { MESSAGE("profile : null direction"); return; } gp_Ax2 ax(P.Location(), vn, vx); P.SetPosition(ax); stayfirst = Standard_True; break; } case 'X': { if (n1 != 2) goto badargs; length = a(1).RealValue(); if (a(0) == "XX") length -= x; dx = 1; dy = 0; move = line; break; } case 'Y': { if (n1 != 2) goto badargs; length = a(1).RealValue(); if (a(0) == "YY") length -= y; dx = 0; dy = 1; move = line; break; } case 'L': { if (n1 != 2) goto badargs; length = a(1).RealValue(); if (Abs(length) > Precision::Confusion()) move = line; else move = none; break; } case 'T': { if (n1 != 3) goto badargs; Standard_Real vx = a(1).RealValue(); Standard_Real vy = a(2).RealValue(); if (a(0) == "TT") { vx -= x; vy -= y; } length = Sqrt(vx * vx + vy * vy); if (length > Precision::Confusion()) { move = line; dx = vx / length; dy = vy / length; } else move = none; break; } case 'R': { if (n1 != 2) goto badargs; angle = a(1).RealValue() * PI180; if (a(0) == "RR") { dx = Cos(angle); dy = Sin(angle); } else { Standard_Real c = Cos(angle); Standard_Real s = Sin(angle); Standard_Real t = c * dx - s * dy; dy = s * dx + c * dy; dx = t; } break; } case 'D': { if (n1 != 3) goto badargs; Standard_Real vx = a(1).RealValue(); Standard_Real vy = a(2).RealValue(); length = Sqrt(vx * vx + vy * vy); if (length > Precision::Confusion()) { dx = vx / length; dy = vy / length; } else move = none; break; } case 'C': { if (n1 != 3) goto badargs; radius = a(1).RealValue(); if (Abs(radius) > Precision::Confusion()) { angle = a(2).RealValue() * PI180; move = circle; } else move = none; break; } case 'A': // TAngential arc by end point { if (n1 != 3) goto badargs; Standard_Real vx = a(1).RealValue(); Standard_Real vy = a(2).RealValue(); if (a(0) == "AA") { vx -= x; vy -= y; } Standard_Real det = dx * vy - dy * vx; if ( Abs(det) > Precision::Confusion()) { Standard_Real c = (dx * vx + dy * vy) / Sqrt((dx * dx + dy * dy) * (vx * vx + vy * vy)); // Cosine of alpha = arc of angle / 2 , alpha in [0,Pi] radius = (vx * vx + vy * vy)* Sqrt(dx * dx + dy * dy) // radius = distance between start and end point / 2 * sin(alpha) / (2.0 * det); // radius is > 0 or < 0 if (Abs(radius) > Precision::Confusion()) { angle = 2.0 * acos(c); // angle in [0,2Pi] move = circle; } else move = none; break; } else move = none; break; } case 'U': // Arc by end point and radiUs { if (n1 != 5) goto badargs; Standard_Real vx = a(1).RealValue(); Standard_Real vy = a(2).RealValue(); radius = a(3).RealValue(); reversed = a(4).IntegerValue(); if (a(0) == "UU") { // Absolute vx -= x; vy -= y; } Standard_Real length = Sqrt(vx * vx + vy * vy); if ( (4.0 - (vx * vx + vy * vy) / (radius * radius) >= 0.0 ) && (length > Precision::Confusion()) ) { Standard_Real c = 0.5 * Sqrt(4.0 - (vx * vx + vy * vy) / (radius * radius)); // Cosine of alpha = arc angle / 2 , alpha in [0,Pi/2] angle = 2.0 * acos(c); // angle in [0,Pi] if ( reversed == 2 ) angle = angle - 2 * PI; dx = 0.5 * ( vy * 1.0/radius + vx * Sqrt(4.0 / (vx * vx + vy * vy) - 1.0 / (radius * radius))); dy = - 0.5 * ( vx * 1.0/radius - vy * Sqrt(4.0 / (vx * vx + vy * vy) - 1.0 / (radius * radius))); move = circle; } else{ move = none; } break; } case 'E': // Arc by end point and cEnter { if (n1 != 7) goto badargs; Standard_Real vx = a(1).RealValue(); Standard_Real vy = a(2).RealValue(); Standard_Real vxc = a(3).RealValue(); Standard_Real vyc = a(4).RealValue(); reversed = a(5).IntegerValue(); control_Tolerance = a(6).IntegerValue(); if (a(0) == "EE") { // Absolute vx -= x; vy -= y; vxc -= x; vyc -= y; } radius = Sqrt( vxc * vxc + vyc * vyc ); Standard_Real det = vx * vyc - vy * vxc; Standard_Real length = Sqrt(vx * vx + vy * vy); Standard_Real length2 = Sqrt((vx-vxc) * (vx-vxc) + (vy-vyc) * (vy-vyc)); Standard_Real length3 = Sqrt(vxc * vxc + vyc * vyc); Standard_Real error = Abs(length2 - radius); myError = error; if ( error > Precision::Confusion() ){ MESSAGE("Warning : The specified end point is not on the Arc, distance = "<<error); } if ( error > Precision::Confusion() && control_Tolerance == 1) // Don't create the arc if the end point move = none; // is too far from it else if ( (length > Precision::Confusion()) && (length2 > Precision::Confusion()) && (length3 > Precision::Confusion()) ) { Standard_Real c = ( radius * radius - (vx * vxc + vy * vyc) ) / ( radius * Sqrt((vx-vxc) * (vx-vxc) + (vy-vyc) * (vy-vyc)) ) ; // Cosine of arc angle angle = acos(c); // angle in [0,Pi] if ( reversed == 2 ) angle = angle - 2 * PI; if (det < 0) angle = -angle; dx = vyc / radius; dy = -vxc / radius; move = circle; } else { move = none; } break; } case 'I': { if (n1 != 2) goto badargs; length = a(1).RealValue(); if (a(0) == "IX") { if (Abs(dx) < Precision::Confusion()) { MESSAGE("profile : cannot intersect, arg "<<i-1); return; } length = (length - x) / dx; } else if (a(0) == "IY") { if (Abs(dy) < Precision::Confusion()) { MESSAGE("profile : cannot intersect, arg "<<i-1); return; } length = (length - y) / dy; } if (Abs(length) > Precision::Confusion()) move = line; else move = none; break; } case 'W': { if (a(0) == "WW") close = Standard_True; else if(a(0) == "WF") { close = Standard_True; face = Standard_True; } i = n - 1; break; } default: { MESSAGE("profile : unknown code " << a(i)); return; } } again : switch (move) { case line : { if (length < 0) { length = -length; dx = -dx; dy = -dy; } Handle(Geom2d_Line) l = new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy)); BRepBuilderAPI_MakeEdge ME (GeomAPI::To3d(l,P),0,length); if (!ME.IsDone()) return; MW.Add(ME); x += length*dx; y += length*dy; break; } case circle : { Standard_Boolean sense = Standard_True; if (radius < 0) { radius = -radius; sense = !sense; dx = -dx; dy = -dy; } gp_Ax2d ax(gp_Pnt2d(x-radius*dy,y+radius*dx),gp_Dir2d(dy,-dx)); if (angle < 0) { angle = -angle; sense = !sense; } Handle(Geom2d_Circle) c = new Geom2d_Circle(ax,radius,sense); BRepBuilderAPI_MakeEdge ME (GeomAPI::To3d(c,P),0,angle); if (!ME.IsDone()) return; MW.Add(ME); gp_Pnt2d p; gp_Vec2d v; c->D1(angle,p,v); x = p.X(); y = p.Y(); dx = v.X() / radius; dy = v.Y() / radius; break; } case point: { MP = BRepBuilderAPI_MakeVertex(gp_Pnt(x, y, 0.0)); break; } case none: { i = n - 1; break; } } // update first first = stayfirst; stayfirst = Standard_False; if(!(dx == 0 && dy == 0)) myLastDir.SetCoord(dx, dy, 0.0); else return; myLastPoint.SetX(x); myLastPoint.SetY(y); // next segment.... i++; if ((i == n) && close) { // the closing segment dx = x0 - x; dy = y0 - y; length = Sqrt(dx * dx + dy * dy); move = line; if (length > Precision::Confusion()) { dx = dx / length; dy = dy / length; goto again; } } } // get the result, face or wire if (move == none) { return; } else if (move == point) { S = MP; } else if (face) { if (!MW.IsDone()) { return; } BRepBuilderAPI_MakeFace MF (P, MW.Wire()); if (!MF.IsDone()) { return; } S = MF; } else { if (!MW.IsDone()) { return; } S = MW; } if(!TheLocation.IsIdentity()) S.Move(TheLocation); myShape = S; myOK = true; return; badargs : MESSAGE("profile : bad number of arguments"); return; }
void OCC_3dDoc::SetDialogTitle(TCollection_AsciiString theTitle) { myCResultDialog.SetTitle(CString(theTitle.ToCString())); }
STEPIMPORT_EXPORT TopoDS_Shape ImportSTEP (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& /*theFormatName*/, TCollection_AsciiString& theError, const TDF_Label& theShapeLabel) { MESSAGE("Import STEP model from file " << theFileName.ToCString()); // Set "C" numeric locale to save numbers correctly //Kernel_Utils::Localizer loc; TopoDS_Shape aResShape; //VRV: OCC 4.0 migration STEPControl_Reader aReader; //VSR: 16/09/09: Convert to METERS Interface_Static::SetCVal("xstep.cascade.unit","M"); Interface_Static::SetIVal("read.step.ideas", 1); Interface_Static::SetIVal("read.step.nonmanifold", 1); //VRV: OCC 4.0 migration TopoDS_Compound compound; BRep_Builder B; B.MakeCompound(compound); try { #if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); if (status == IFSelect_RetDone) { Standard_Boolean failsonly = Standard_False; aReader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity); /* Root transfers */ Standard_Integer nbr = aReader.NbRootsForTransfer(); aReader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity); for (Standard_Integer n = 1; n <= nbr; n++) { Standard_Boolean ok = aReader.TransferRoot(n); /* Collecting resulting entities */ Standard_Integer nbs = aReader.NbShapes(); if (!ok || nbs == 0) { // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM); continue; // skip empty root } /* For a single entity */ else if (nbr == 1 && nbs == 1) { aResShape = aReader.Shape(1); // ATTENTION: this is a workaround for mantis issue 0020442 remark 0010776 // It should be removed after patching OCCT for bug OCC22436 // (fix for OCCT is expected in service pack next to OCCT6.3sp12) if (aResShape.ShapeType() == TopAbs_COMPOUND) { int nbSub1 = 0; TopoDS_Shape currShape; TopoDS_Iterator It (aResShape, Standard_True, Standard_True); for (; It.More(); It.Next()) { nbSub1++; currShape = It.Value(); } if (nbSub1 == 1) aResShape = currShape; } // END workaround break; } for (Standard_Integer i = 1; i <= nbs; i++) { TopoDS_Shape aShape = aReader.Shape(i); if (aShape.IsNull()) { // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ; //return aResShape; continue; } else { B.Add(compound, aShape); } } } if (aResShape.IsNull()) aResShape = compound; // BEGIN: Store names of sub-shapes from file TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(aResShape, anIndices); Handle(Interface_InterfaceModel) Model = aReader.WS()->Model(); Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader(); if (!TR.IsNull()) { Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition); Handle(Standard_Type) tShape = STANDARD_TYPE(StepShape_TopologicalRepresentationItem); Handle(Standard_Type) tGeom = STANDARD_TYPE(StepGeom_GeometricRepresentationItem); Standard_Integer nb = Model->NbEntities(); for (Standard_Integer ie = 1; ie <= nb; ie++) { Handle(Standard_Transient) enti = Model->Value(ie); Handle(TCollection_HAsciiString) aName; if ( enti->IsKind( tShape ) || enti->IsKind(tGeom)) { aName = Handle(StepRepr_RepresentationItem)::DownCast(enti)->Name(); } else if (enti->DynamicType() == tPD) { Handle(StepBasic_ProductDefinition) PD = Handle(StepBasic_ProductDefinition)::DownCast(enti); if (PD.IsNull()) continue; Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct(); aName = Prod->Name(); } else { continue; } if ( aName->UsefullLength() < 1 ) continue; // skip 'N0NE' name if ( aName->UsefullLength() == 4 && toupper (aName->Value(1)) == 'N' && toupper (aName->Value(2)) == 'O' && toupper (aName->Value(3)) == 'N' && toupper (aName->Value(4)) == 'E') continue; // special check to pass names like "Open CASCADE STEP translator 6.3 1" TCollection_AsciiString aSkipName ("Open CASCADE STEP translator"); if (aName->Length() >= aSkipName.Length()) { if (aName->String().SubString(1, aSkipName.Length()).IsEqual(aSkipName)) continue; } TCollection_ExtendedString aNameExt (aName->ToCString()); // find target shape Handle(Transfer_Binder) binder = TP->Find(enti); if (binder.IsNull()) continue; TopoDS_Shape S = TransferBRep::ShapeResult(binder); if (S.IsNull()) continue; // as PRODUCT can be included in the main shape // several times, we look here for all iclusions. Standard_Integer isub, nbSubs = anIndices.Extent(); for (isub = 1; isub <= nbSubs; isub++) { TopoDS_Shape aSub = anIndices.FindKey(isub); if (aSub.IsPartner(S)) { TDF_Label L; if (enti->IsKind(tGeom)) { // check all named shapes using iterator TDF_ChildIDIterator anIt (theShapeLabel, TDataStd_Name::GetID(), Standard_True); for (; anIt.More(); anIt.Next()) { Handle(TDataStd_Name) nameAttr = Handle(TDataStd_Name)::DownCast(anIt.Value()); if (nameAttr.IsNull()) continue; TDF_Label Lab = nameAttr->Label(); Handle(TNaming_NamedShape) shAttr; if (Lab.FindAttribute(TNaming_NamedShape::GetID(), shAttr) && shAttr->Get().IsEqual(aSub)) L = Lab; } } // create label and set shape if (L.IsNull()) { TDF_TagSource aTag; L = aTag.NewChild(theShapeLabel); TNaming_Builder tnBuild (L); //tnBuild.Generated(S); tnBuild.Generated(aSub); } // set a name TDataStd_Name::Set(L, aNameExt); } } } } // END: Store names } else { // switch (status) { // case IFSelect_RetVoid: // theError = "Nothing created or No data to process"; // break; // case IFSelect_RetError: // theError = "Error in command or input data"; // break; // case IFSelect_RetFail: // theError = "Execution was run, but has failed"; // break; // case IFSelect_RetStop: // theError = "Execution has been stopped. Quite possible, an exception was raised"; // break; // default: // break; // } theError = "Wrong format of the imported file. Can't import file."; aResShape.Nullify(); } } catch (Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); theError = aFail->GetMessageString(); aResShape.Nullify(); } // Return previous locale return aResShape; }
void CViewer3dDoc::UpdateResultMessageDlg (CString theTitle, const TCollection_AsciiString& theMessage) { CString aText (theMessage.ToCString()); myCResultDialog.SetText (aText); myCResultDialog.SetTitle(theTitle); }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_VectorDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IVector aPI (aFunction); Standard_Integer aType = aFunction->GetType(); if (aType != VECTOR_DX_DY_DZ && aType != VECTOR_TWO_PNT && aType != VECTOR_TANGENT_CURVE_PAR && aType != VECTOR_REVERSE) return 0; TopoDS_Shape aShape; if (aType == VECTOR_DX_DY_DZ) { gp_Pnt P1 = gp::Origin(); gp_Pnt P2 (aPI.GetDX(), aPI.GetDY(), aPI.GetDZ()); if (P1.Distance(P2) < Precision::Confusion()) { TCollection_AsciiString aMsg ("Can not build vector with length, less than "); aMsg += TCollection_AsciiString(Precision::Confusion()); Standard_ConstructionError::Raise(aMsg.ToCString()); } aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape(); } else if (aType == VECTOR_TWO_PNT) { Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1(); Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2(); TopoDS_Shape aShape1 = aRefPnt1->GetValue(); TopoDS_Shape aShape2 = aRefPnt2->GetValue(); if (aShape1.ShapeType() != TopAbs_VERTEX || aShape2.ShapeType() != TopAbs_VERTEX) return 0; if (aShape1.IsSame(aShape2)) { Standard_ConstructionError::Raise("The end points must be different"); } TopoDS_Vertex V1 = TopoDS::Vertex(aShape1); TopoDS_Vertex V2 = TopoDS::Vertex(aShape2); gp_Pnt P1 = BRep_Tool::Pnt(V1); gp_Pnt P2 = BRep_Tool::Pnt(V2); if (P1.Distance(P2) < Precision::Confusion()) { Standard_ConstructionError::Raise("The end points are too close"); } aShape = BRepBuilderAPI_MakeEdge(V1, V2).Shape(); } else if (aType == VECTOR_TANGENT_CURVE_PAR) { Handle(GEOM_Function) aRefCurve = aPI.GetCurve(); TopoDS_Shape aRefShape = aRefCurve->GetValue(); if (aRefShape.ShapeType() != TopAbs_EDGE) { Standard_TypeMismatch::Raise ("Tangent On Curve creation aborted : curve shape is not an edge"); } Standard_Real aFParam =0., aLParam =0., aParam =0.; Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aRefShape), aFParam, aLParam); if(aCurve.IsNull()) { Standard_TypeMismatch::Raise ("Tangent On Curve creation aborted : curve is null"); } aParam = aFParam + (aLParam - aFParam) * aPI.GetParameter(); gp_Pnt aPoint1,aPoint2; gp_Vec aVec; aCurve->D1(aParam,aPoint1,aVec); if(aVec.Magnitude() < gp::Resolution()) Standard_TypeMismatch::Raise ("Tangent On Curve creation aborted : invalid value of tangent"); aPoint2.SetXYZ(aPoint1.XYZ() + aVec.XYZ()); BRepBuilderAPI_MakeEdge aBuilder(aPoint1,aPoint2); if(aBuilder.IsDone()) aShape = aBuilder.Shape(); } else if (aType == VECTOR_REVERSE) { Handle(GEOM_Function) aRefVec = aPI.GetCurve(); TopoDS_Shape aRefShape = aRefVec->GetValue(); if (aRefShape.ShapeType() != TopAbs_EDGE) { Standard_TypeMismatch::Raise ("Reversed vector creation aborted : vector shape is not an edge"); } TopoDS_Edge anE = TopoDS::Edge(aRefShape); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); aShape = BRepBuilderAPI_MakeEdge(V2, V1).Shape(); } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }