mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
Modificarion STEP translator for ISCAR project
Modification for loading a few STEP files in the model
This commit is contained in:
@@ -212,7 +212,7 @@ IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile
|
||||
{
|
||||
if (thelibrary.IsNull()) return IFSelect_RetVoid;
|
||||
if (theprotocol.IsNull()) return IFSelect_RetVoid;
|
||||
Handle(Interface_InterfaceModel) model;
|
||||
Handle(Interface_InterfaceModel) model =myModel;
|
||||
IFSelect_ReturnStatus status = IFSelect_RetVoid;
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
@@ -1701,11 +1701,12 @@ Standard_Integer IFSelect_WorkSession::RunTransformer
|
||||
{
|
||||
Standard_Integer effect = 0;
|
||||
if (transf.IsNull() || !IsLoaded()) return effect;
|
||||
|
||||
Handle(Interface_InterfaceModel) newmod; // Null au depart
|
||||
Interface_CheckIterator checks;
|
||||
checks.SetName("X-STEP WorkSession : RunTransformer");
|
||||
Standard_Boolean res = transf->Perform
|
||||
(thegraph->Graph(),theprotocol,checks,newmod);
|
||||
(thegraph->Graph(),theprotocol,checks,myModel);
|
||||
|
||||
if (!checks.IsEmpty(Standard_False)) {
|
||||
Handle(Message_Messenger) sout = Message::DefaultMessenger();
|
||||
|
@@ -52,14 +52,18 @@ void RWStepVisual_RWPresentationLayerAssignment::ReadStep
|
||||
Handle(StepVisual_HArray1OfLayeredItem) aAssignedItems;
|
||||
StepVisual_LayeredItem aAssignedItemsItem;
|
||||
Standard_Integer nsub3;
|
||||
if (data->ReadSubList (num,3,"assigned_items",ach,nsub3)) {
|
||||
Standard_Integer nb3 = data->NbParams(nsub3);
|
||||
aAssignedItems = new StepVisual_HArray1OfLayeredItem (1, nb3);
|
||||
for (Standard_Integer i3 = 1; i3 <= nb3; i3 ++) {
|
||||
//szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
|
||||
if (data->ReadEntity (nsub3,i3,"assigned_items",ach,aAssignedItemsItem))
|
||||
aAssignedItems->SetValue(i3,aAssignedItemsItem);
|
||||
}
|
||||
if (data->ReadSubList(num, 3, "assigned_items", ach, nsub3)) {
|
||||
Standard_Integer nb3 = data->NbParams(nsub3);
|
||||
if (nb3)
|
||||
{
|
||||
|
||||
aAssignedItems = new StepVisual_HArray1OfLayeredItem(1, nb3);
|
||||
for (Standard_Integer i3 = 1; i3 <= nb3; i3++) {
|
||||
//szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
|
||||
if (data->ReadEntity(nsub3, i3, "assigned_items", ach, aAssignedItemsItem))
|
||||
aAssignedItems->SetValue(i3, aAssignedItemsItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--- Initialisation of the read entity ---
|
||||
|
@@ -141,11 +141,22 @@ void StepData_StepModel::SetIdentLabel
|
||||
Standard_Integer num = Number(ent);
|
||||
if (!num)
|
||||
return;
|
||||
Standard_Integer nbEnt = NbEntities();
|
||||
if(theidnums.IsNull())
|
||||
{
|
||||
theidnums = new TColStd_HArray1OfInteger(1, NbEntities());
|
||||
theidnums = new TColStd_HArray1OfInteger(1,nbEnt);
|
||||
theidnums->Init(0);
|
||||
}
|
||||
else if(nbEnt > theidnums->Length())
|
||||
{
|
||||
Standard_Integer prevLength = theidnums->Length();
|
||||
Handle(TColStd_HArray1OfInteger) idnums1 = new TColStd_HArray1OfInteger(1,nbEnt);
|
||||
idnums1->Init(0);
|
||||
Standard_Integer k =1;
|
||||
for( ; k <= prevLength; k++)
|
||||
idnums1->SetValue(k , theidnums->Value(k));
|
||||
theidnums = idnums1;
|
||||
}
|
||||
theidnums->SetValue(num,ident);
|
||||
|
||||
}
|
||||
|
@@ -1017,8 +1017,8 @@ Standard_Boolean StepData_StepReaderData::ReadReal(const Standard_Integer num,
|
||||
Handle(String) errmess; // Null si pas d erreur
|
||||
if (nump > 0 && nump <= NbParams(num)) {
|
||||
const Interface_FileParameter& FP = Param(num,nump);
|
||||
if (FP.ParamType() == Interface_ParamReal) val =
|
||||
Interface_FileReaderData::Fastof(FP.CValue());
|
||||
if (FP.ParamType() == Interface_ParamReal || FP.ParamType() == Interface_ParamInteger)
|
||||
val = Interface_FileReaderData::Fastof(FP.CValue());
|
||||
else errmess = new String("Parameter n0.%d (%s) not a Real");
|
||||
}
|
||||
else errmess = new String("Parameter n0.%d (%s) absent");
|
||||
|
@@ -70,8 +70,16 @@ Standard_Integer StepSelect_WorkLibrary::ReadFile
|
||||
long status = 1;
|
||||
DeclareAndCast(StepData_Protocol,stepro,protocol);
|
||||
if (stepro.IsNull()) return 1;
|
||||
Handle(StepData_StepModel) stepmodel = new StepData_StepModel;
|
||||
model = stepmodel;
|
||||
//ISCAR
|
||||
Handle(StepData_StepModel) stepmodel;
|
||||
if(!model.IsNull())
|
||||
stepmodel = Handle(StepData_StepModel)::DownCast(model);
|
||||
if(stepmodel.IsNull())
|
||||
{
|
||||
stepmodel = new StepData_StepModel;
|
||||
model = stepmodel;
|
||||
}
|
||||
|
||||
StepFile_ReadTrace (0);
|
||||
char *pName=(char *)name;
|
||||
status = StepFile_Read (pName,stepmodel,stepro);
|
||||
|
@@ -70,5 +70,5 @@ StepVisual_LayeredItem StepVisual_PresentationLayerAssignment::AssignedItemsValu
|
||||
|
||||
Standard_Integer StepVisual_PresentationLayerAssignment::NbAssignedItems () const
|
||||
{
|
||||
return assignedItems->Length();
|
||||
return (assignedItems.IsNull() ? 0 : assignedItems->Length());
|
||||
}
|
||||
|
@@ -47,6 +47,8 @@
|
||||
#include <XCAFDoc_Editor.hxx>
|
||||
#include <TDF_Tool.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <StepData_StepModel.hxx>
|
||||
#include <Interface_Static.hxx>
|
||||
|
||||
#include <stdio.h>
|
||||
//============================================================
|
||||
@@ -512,6 +514,87 @@ static Standard_Integer Expand (Draw_Interpretor& di, Standard_Integer argc, con
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static Standard_Integer testSTEP(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
|
||||
{
|
||||
if (argc <3) {
|
||||
di << "Use: " << argv[0] << " Doc filename [mode]: read STEP file to a document\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
DeclareAndCast(STEPControl_Controller, ctl, XSDRAW::Controller());
|
||||
if (ctl.IsNull()) XSDRAW::SetNorm("STEP");
|
||||
|
||||
STEPCAFControl_Reader reader(XSDRAW::Session(), Standard_True);
|
||||
|
||||
if (argc == 4) {
|
||||
Standard_Boolean mode = Standard_True;
|
||||
for (Standard_Integer i = 0; argv[3][i]; i++)
|
||||
switch (argv[3][i]) {
|
||||
case '-': mode = Standard_False; break;
|
||||
case '+': mode = Standard_True; break;
|
||||
case 'c': reader.SetColorMode(mode); break;
|
||||
case 'n': reader.SetNameMode(mode); break;
|
||||
case 'l': reader.SetLayerMode(mode); break;
|
||||
case 'v': reader.SetPropsMode(mode); break;
|
||||
}
|
||||
}
|
||||
|
||||
TCollection_AsciiString fnom, rnom;
|
||||
Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "STEP", fnom, rnom);
|
||||
if (modfic) di << " File STEP to read : " << fnom.ToCString() << "\n";
|
||||
else di << " Model taken from the session : " << fnom.ToCString() << "\n";
|
||||
// di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom<<"\n";
|
||||
IFSelect_ReturnStatus readstat = IFSelect_RetVoid;
|
||||
if (modfic) readstat = reader.ReadFile(fnom.ToCString());
|
||||
else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone;
|
||||
if (readstat != IFSelect_RetDone) {
|
||||
if (modfic) di << "Could not read file " << fnom.ToCString() << " , abandon\n";
|
||||
else di << "No model loaded\n";
|
||||
return 1;
|
||||
}
|
||||
////////////////////////////////////////////////////////
|
||||
//Modification for Drawing2.stp
|
||||
Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(reader.ChangeReader().Model());
|
||||
Standard_Integer i = 1 , nbEnt = aModel->NbEntities();
|
||||
for (; i <= nbEnt; i++)
|
||||
{
|
||||
Handle(Standard_Transient) ent = aModel->Value(i);
|
||||
if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition)))
|
||||
break;
|
||||
}
|
||||
//product defintion is not found
|
||||
if (i > nbEnt)
|
||||
Interface_Static::SetIVal("read.step.all.shapes", 1);
|
||||
else
|
||||
Interface_Static::SetIVal("read.step.all.shapes", 0);
|
||||
reader.NbRootsForTransfer();
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
Handle(TDocStd_Document) doc;
|
||||
if (!DDocStd::GetDocument(argv[1], doc, Standard_False)) {
|
||||
Handle(TDocStd_Application) A = DDocStd::GetApplication();
|
||||
A->NewDocument("BinXCAF", doc);
|
||||
TDataStd_Name::Set(doc->GetData()->Root(), argv[1]);
|
||||
Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
|
||||
Draw::Set(argv[1], DD);
|
||||
// di << "Document saved with name " << argv[1];
|
||||
}
|
||||
if (!reader.Transfer(doc)) {
|
||||
di << "Cannot read any relevant data from the STEP file\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
|
||||
Draw::Set(argv[1], DD);
|
||||
di << "Document saved with name " << argv[1];
|
||||
|
||||
NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> DicFile = reader.ExternFiles();
|
||||
FillDicWS(DicFile);
|
||||
AddWS(fnom, XSDRAW::Session());
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void XDEDRAW_Common::InitCommands(Draw_Interpretor& di)
|
||||
{
|
||||
@@ -537,4 +620,6 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di)
|
||||
di.Add("XExpand", "XExpand Doc recursively(0/1) or XExpand Doc recursively(0/1) label1 abel2 ..."
|
||||
"or XExpand Doc recursively(0/1) shape1 shape2 ...",__FILE__, Expand, g);
|
||||
|
||||
di.Add("TestStep", "Doc filename: Read STEP file to DECAF document", __FILE__, testSTEP, g);
|
||||
|
||||
}
|
||||
|
@@ -49,6 +49,8 @@
|
||||
#include <XSControl_WorkSession.hxx>
|
||||
#include <XSDRAW.hxx>
|
||||
#include <XSDRAWSTEP.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
|
||||
#include <stdio.h>
|
||||
// Pour le transfert (write)
|
||||
@@ -272,26 +274,75 @@ static Standard_Integer stepread (Draw_Interpretor& di/*theCommands*/, Standard_
|
||||
//=======================================================================
|
||||
static Standard_Integer testread (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
|
||||
{
|
||||
if (argc != 3)
|
||||
if (argc < 3)
|
||||
{
|
||||
di << "ERROR in " << argv[0] << "Wrong Number of Arguments.\n";
|
||||
di << " Usage : " << argv[0] <<" file_name shape_name\n";
|
||||
return 1;
|
||||
}
|
||||
STEPControl_Reader Reader;
|
||||
Standard_CString filename = argv[1];
|
||||
IFSelect_ReturnStatus readstat = Reader.ReadFile(filename);
|
||||
di<<"Status from reading STEP file "<<filename<<" : ";
|
||||
switch(readstat) {
|
||||
Standard_Integer k =2;
|
||||
for( ; k < argc; k++)
|
||||
{
|
||||
Standard_CString filename = argv[k];
|
||||
IFSelect_ReturnStatus readstat = Reader.ReadFile(filename);
|
||||
|
||||
|
||||
/* di<<"Status from reading STEP file "<<filename<<" : ";
|
||||
switch(readstat) {
|
||||
case IFSelect_RetVoid : { di<<"empty file\n"; return 1; }
|
||||
case IFSelect_RetDone : { di<<"file read\n"; break; }
|
||||
case IFSelect_RetError : { di<<"file not found\n"; return 1; }
|
||||
case IFSelect_RetFail : { di<<"error during read\n"; return 1; }
|
||||
default : { di<<"failure\n"; return 1; }
|
||||
} */
|
||||
Standard_Integer nbEnt1 = Reader.Model()->NbEntities();
|
||||
//di<<"Number of entities : "<<k<<" "<<nbEnt1<<"\n";
|
||||
}
|
||||
Reader.TransferRoots();
|
||||
TopoDS_Shape shape = Reader.OneShape();
|
||||
DBRep::Set(argv[2],shape);
|
||||
|
||||
Standard_Integer nbEnt = Reader.Model()->NbEntities();
|
||||
/* di<<"Sum number of entities : "<<nbEnt<<"\n";
|
||||
STEPControl_Writer Writer(Reader.WS(), Standard_False);
|
||||
TCollection_AsciiString filename_out = "Result.stp";
|
||||
Writer.Write(filename_out);*/
|
||||
Standard_Integer nbRoots = Reader.TransferRoots();
|
||||
//Standard_Integer k =1;
|
||||
TopoDS_Compound aComp;
|
||||
BRep_Builder aB;
|
||||
aB.MakeCompound(aComp);
|
||||
gp_Pnt aP1(0.,0.,0.);
|
||||
for ( k =1; k <= nbRoots; k++)
|
||||
{
|
||||
if(Reader.TransferRoot(k))
|
||||
{
|
||||
TopoDS_Shape shape = Reader.Shape(k);
|
||||
if( k == nbRoots)
|
||||
{
|
||||
gp_Trsf aT1;
|
||||
gp_Pnt aP2(10.,0.,0.);
|
||||
aT1.SetTranslation(aP1, aP2);
|
||||
TopLoc_Location aLoc(aT1);
|
||||
TopoDS_Shape aSh1= shape.Moved(aLoc);
|
||||
aB.Add(aComp, aSh1);
|
||||
gp_Trsf aT2;
|
||||
gp_Pnt aP3(20.,0.,0.);
|
||||
aT2.SetTranslation(aP1, aP3);
|
||||
TopLoc_Location aLoc2(aT2);
|
||||
TopoDS_Shape aSh2= shape.Moved(aLoc2);
|
||||
aB.Add(aComp, aSh2);
|
||||
|
||||
}
|
||||
else
|
||||
aB.Add(aComp, shape);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TopoDS_Shape shape = Reader.OneShape();
|
||||
|
||||
DBRep::Set(argv[1],aComp);
|
||||
di<<"Count of shapes produced : "<<Reader.NbShapes()<<"\n";
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user