From 47263fa6a30894e7175208183eaefb263057699d Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Thu, 26 Jan 2023 15:24:07 +0000 Subject: [PATCH] 0033317: Data Exchange, Step Export - Ignoring color attached to the reference shape label Fixed problem with pure referencing. To export reference label to step we convert it to the assembly with one part. All attributes attached to the label should be moved to the new part. For working with it new map contains only pure reference labels, that converted to the part was implemented to the STEPCAFControl_Writer. Updated code style of the STEPCAFControl_Writer Improved ability to export labels from different documents Removed OCCT_Debug macros to print in Trace gravity --- src/STEPCAFControl/STEPCAFControl_Writer.cxx | 4630 +++++++++--------- src/STEPCAFControl/STEPCAFControl_Writer.hxx | 289 +- src/XCAFDoc/XCAFDoc_ColorTool.cxx | 8 +- src/XCAFDoc/XCAFDoc_ColorTool.hxx | 10 +- src/XCAFDoc/XCAFDoc_DimTolTool.cxx | 6 +- src/XCAFDoc/XCAFDoc_DimTolTool.hxx | 14 +- src/XCAFDoc/XCAFDoc_LayerTool.cxx | 16 +- src/XCAFDoc/XCAFDoc_LayerTool.hxx | 2 +- src/XCAFDoc/XCAFDoc_MaterialTool.cxx | 2 +- src/XCAFDoc/XCAFDoc_MaterialTool.hxx | 2 +- src/XCAFDoc/XCAFDoc_VisMaterialTool.cxx | 10 +- src/XCAFDoc/XCAFDoc_VisMaterialTool.hxx | 4 +- tests/bugs/step/bug33317 | 32 + 13 files changed, 2560 insertions(+), 2465 deletions(-) create mode 100644 tests/bugs/step/bug33317 diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index 521d043df4..b9c9a2bee7 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -216,57 +216,35 @@ #include #include -// added by skl 15.01.2004 for D> writing -//#include -//#include -// added by skl 12.02.2004 for writing materials //======================================================================= //function : GetLabelName //purpose : auxiliary function: take name of label and append it to str //======================================================================= -static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAsciiString) &str) +static Standard_Boolean GetLabelName(const TDF_Label& theL, + Handle(TCollection_HAsciiString)& theStr) { - Handle(TDataStd_Name) N; - if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) return Standard_False; - TCollection_ExtendedString name = N->Get(); - if ( name.Length() <=0 ) return Standard_False; + Handle(TDataStd_Name) anAttrName; + if (!theL.FindAttribute(TDataStd_Name::GetID(), anAttrName)) + { + return Standard_False; + } + TCollection_ExtendedString aName = anAttrName->Get(); + if (aName.IsEmpty()) + return Standard_False; // set name, removing spaces around it - TCollection_AsciiString buf(name); - buf.LeftAdjust(); - buf.RightAdjust(); - str->AssignCat ( buf.ToCString() ); + TCollection_AsciiString aBuffer(aName); + aBuffer.LeftAdjust(); + aBuffer.RightAdjust(); + theStr->AssignCat(aBuffer.ToCString()); return Standard_True; } - //======================================================================= //function : STEPCAFControl_Writer //purpose : //======================================================================= - -STEPCAFControl_Writer::STEPCAFControl_Writer () : - myColorMode( Standard_True ), - myNameMode ( Standard_True ), - myLayerMode( Standard_True ), - myPropsMode( Standard_True ), - mySHUOMode ( Standard_True ), - myGDTMode ( Standard_True ), - myMatMode ( Standard_True ) -{ - STEPCAFControl_Controller::Init(); - Handle(XSControl_WorkSession) WS = new XSControl_WorkSession; - Init ( WS ); -} - - -//======================================================================= -//function : STEPCAFControl_Writer -//purpose : -//======================================================================= - -STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession)& WS, - const Standard_Boolean scratch) : +STEPCAFControl_Writer::STEPCAFControl_Writer() : myColorMode(Standard_True), myNameMode(Standard_True), myLayerMode(Standard_True), @@ -276,35 +254,53 @@ STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession myMatMode(Standard_True) { STEPCAFControl_Controller::Init(); - Init ( WS, scratch ); + Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession; + Init(aWS); } +//======================================================================= +//function : STEPCAFControl_Writer +//purpose : +//======================================================================= +STEPCAFControl_Writer::STEPCAFControl_Writer(const Handle(XSControl_WorkSession)& theWS, + const Standard_Boolean theScratch) : + myColorMode(Standard_True), + myNameMode(Standard_True), + myLayerMode(Standard_True), + myPropsMode(Standard_True), + mySHUOMode(Standard_True), + myGDTMode(Standard_True), + myMatMode(Standard_True) +{ + STEPCAFControl_Controller::Init(); + Init(theWS, theScratch); +} //======================================================================= //function : Init //purpose : //======================================================================= - -void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS, - const Standard_Boolean scratch) +void STEPCAFControl_Writer::Init(const Handle(XSControl_WorkSession)& theWS, + const Standard_Boolean theScratch) { - WS->SelectNorm ( "STEP" ); - myWriter.SetWS (WS,scratch); + theWS->SelectNorm("STEP"); + myWriter.SetWS(theWS, theScratch); myFiles.Clear(); myLabEF.Clear(); myLabels.Clear(); + myPureRefLabels.Clear(); + myRootLabels.Clear(); myGDTPresentationDM = new StepVisual_DraughtingModel(); myGDTPrsCurveStyle = new StepVisual_HArray1OfPresentationStyleAssignment(1, 1); } - //======================================================================= //function : Write //purpose : //======================================================================= -IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString theFileName) +IFSelect_ReturnStatus STEPCAFControl_Writer::Write(const Standard_CString theFileName) { - IFSelect_ReturnStatus aStatus = myWriter.Write (theFileName); + IFSelect_ReturnStatus aStatus = myWriter.Write(theFileName); if (aStatus != IFSelect_RetDone) { return aStatus; @@ -313,13 +309,13 @@ IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString theFi // get directory name of the main file TCollection_AsciiString aDirPath; { - OSD_Path aMainFile (theFileName); - aMainFile.SetName (""); - aMainFile.SetExtension (""); - aMainFile.SystemName (aDirPath); + OSD_Path aMainFile(theFileName); + aMainFile.SetName(""); + aMainFile.SetExtension(""); + aMainFile.SystemName(aDirPath); } - for (NCollection_DataMap::Iterator anExtFileIter (myFiles); + for (NCollection_DataMap::Iterator anExtFileIter(myFiles); anExtFileIter.More(); anExtFileIter.Next()) { Handle(STEPCAFControl_ExternFile) anExtFile = anExtFileIter.Value(); @@ -329,17 +325,15 @@ IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString theFi } // construct extern file name - TCollection_AsciiString aFileName = OSD_Path::AbsolutePath (aDirPath, anExtFile->GetName()->String()); + TCollection_AsciiString aFileName = OSD_Path::AbsolutePath(aDirPath, anExtFile->GetName()->String()); if (aFileName.Length() <= 0) { aFileName = anExtFile->GetName()->String(); } -#ifdef OCCT_DEBUG - std::cout << "Writing external file: " << aFileName << std::endl; -#endif - - const IFSelect_ReturnStatus anExtStatus = anExtFile->GetWS()->SendAll (aFileName.ToCString()); - anExtFile->SetWriteStatus (anExtStatus); + Message::SendTrace() << "Writing external file: " << aFileName << "\n"; + + const IFSelect_ReturnStatus anExtStatus = anExtFile->GetWS()->SendAll(aFileName.ToCString()); + anExtFile->SetWriteStatus(anExtStatus); if (anExtStatus != IFSelect_RetDone) { aStatus = anExtStatus; @@ -358,7 +352,7 @@ void STEPCAFControl_Writer::prepareUnit(const TDF_Label& theLabel, { Handle(XCAFDoc_LengthUnit) aLengthAttr; if (!theLabel.IsNull() && - theLabel.Root().FindAttribute(XCAFDoc_LengthUnit::GetID(), aLengthAttr)) + theLabel.Root().FindAttribute(XCAFDoc_LengthUnit::GetID(), aLengthAttr)) { theModel->SetLocalLengthUnit(aLengthAttr->GetUnitValue() * 1000); // convert to mm } @@ -373,7 +367,7 @@ void STEPCAFControl_Writer::prepareUnit(const TDF_Label& theLabel, //function : WriteStream //purpose : //======================================================================= -IFSelect_ReturnStatus STEPCAFControl_Writer::WriteStream (std::ostream& theStream) +IFSelect_ReturnStatus STEPCAFControl_Writer::WriteStream(std::ostream& theStream) { if (!myFiles.IsEmpty()) { @@ -381,185 +375,167 @@ IFSelect_ReturnStatus STEPCAFControl_Writer::WriteStream (std::ostream& theStrea return IFSelect_RetError; } - return myWriter.WriteStream (theStream); + return myWriter.WriteStream(theStream); } //======================================================================= //function : Transfer //purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::Transfer(const Handle(TDocStd_Document) &doc, - const STEPControl_StepModelType mode, - const Standard_CString multi, +Standard_Boolean STEPCAFControl_Writer::Transfer(const Handle(TDocStd_Document)& theDoc, + const STEPControl_StepModelType theMode, + const Standard_CString theMulti, const Message_ProgressRange& theProgress) { - Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() ); - if ( STool.IsNull() ) return Standard_False; - - TDF_LabelSequence labels; - STool->GetFreeShapes ( labels ); - return Transfer(myWriter, labels, mode, multi, Standard_False, theProgress); -} - - -//======================================================================= -//function : Transfer -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_Label& L, - const STEPControl_StepModelType mode, - const Standard_CString multi, - const Message_ProgressRange& theProgress) -{ - TDF_LabelSequence labels; - labels.Append ( L ); - return Transfer(myWriter, labels, mode, multi, Standard_False, theProgress); -} - -//======================================================================= -//function : Transfer -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_LabelSequence& labels, - const STEPControl_StepModelType mode, - const Standard_CString multi, - const Message_ProgressRange& theProgress) -{ - return Transfer(myWriter, labels, mode, multi, Standard_False, theProgress); -} - -//======================================================================= -//function : Perform -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc, - const Standard_CString filename, - const Message_ProgressRange& theProgress) -{ - if (!Transfer(doc, STEPControl_AsIs, 0L, theProgress)) return Standard_False; - return Write ( filename ) == IFSelect_RetDone; -} - - -//======================================================================= -//function : Perform -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc, - const TCollection_AsciiString &filename, - const Message_ProgressRange& theProgress) -{ - if ( ! Transfer ( doc, STEPControl_AsIs, 0L, theProgress ) ) return Standard_False; - return Write ( filename.ToCString() ) == IFSelect_RetDone; -} - - -//======================================================================= -//function : ExternFiles -//purpose : -//======================================================================= - -const NCollection_DataMap& STEPCAFControl_Writer::ExternFiles () const -{ - return myFiles; -} - - -//======================================================================= -//function : ExternFile -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::ExternFile (const TDF_Label &L, - Handle(STEPCAFControl_ExternFile) &ef) const -{ - ef.Nullify(); - if ( ! myLabEF.IsBound ( L ) ) return Standard_False; - ef = myLabEF.Find ( L ); - return Standard_True; -} - - -//======================================================================= -//function : ExternFile -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::ExternFile (const Standard_CString name, - Handle(STEPCAFControl_ExternFile) &ef) const -{ - ef.Nullify(); - if ( ! myFiles.IsEmpty() || ! myFiles.IsBound ( name ) ) + Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()); + if (aShTool.IsNull()) return Standard_False; - ef = myFiles.Find( name ); - return Standard_True; + + myRootLabels.Clear(); + myRootLabels.Add(theDoc->Main().Root()); + TDF_LabelSequence aLabels; + aShTool->GetFreeShapes(aLabels); + return transfer(myWriter, aLabels, theMode, theMulti, Standard_False, theProgress); } - -//======================================================================= -//function : Writer -//purpose : -//======================================================================= - -STEPControl_Writer &STEPCAFControl_Writer::ChangeWriter () -{ - return myWriter; -} - - -//======================================================================= -//function : Writer -//purpose : -//======================================================================= - -const STEPControl_Writer &STEPCAFControl_Writer::Writer () const -{ - return myWriter; -} - - //======================================================================= //function : Transfer //purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer, - const TDF_LabelSequence &labels, - const STEPControl_StepModelType mode, - const Standard_CString multi, - const Standard_Boolean isExternFile, - const Message_ProgressRange& theProgress) +Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_Label& theLabel, + const STEPControl_StepModelType theMode, + const Standard_CString theIsMulti, + const Message_ProgressRange& theProgress) { - if ( labels.Length() <=0 ) return Standard_False; + if (theLabel.IsNull()) + { + return Standard_False; + } + TDF_LabelSequence aLabels; + aLabels.Append(theLabel); + myRootLabels.Clear(); + myRootLabels.Add(theLabel.Root()); + return transfer(myWriter, aLabels, theMode, theIsMulti, Standard_False, theProgress); +} - Handle(STEPCAFControl_ActorWrite) Actor = - Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() ); +//======================================================================= +//function : Transfer +//purpose : +//======================================================================= +Standard_Boolean STEPCAFControl_Writer::Transfer(const TDF_LabelSequence& theLabels, + const STEPControl_StepModelType theMode, + const Standard_CString theIsMulti, + const Message_ProgressRange& theProgress) +{ + myRootLabels.Clear(); + for (TDF_LabelSequence::Iterator aLabelIter(theLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + if (!aLabel.IsNull()) + { + myRootLabels.Add(aLabel.Root()); + } + } + return transfer(myWriter, theLabels, theMode, theIsMulti, Standard_False, theProgress); +} - const Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(writer.WS()->Model()); - prepareUnit(labels.First(), aModel); // set local length unit to the model +//======================================================================= +//function : Perform +//purpose : +//======================================================================= +Standard_Boolean STEPCAFControl_Writer::Perform(const Handle(TDocStd_Document)& theDoc, + const Standard_CString theFileName, + const Message_ProgressRange& theProgress) +{ + if (!Transfer(theDoc, STEPControl_AsIs, 0L, theProgress)) + return Standard_False; + return Write(theFileName) == IFSelect_RetDone; +} + +//======================================================================= +//function : Perform +//purpose : +//======================================================================= +Standard_Boolean STEPCAFControl_Writer::Perform(const Handle(TDocStd_Document)& theDoc, + const TCollection_AsciiString& theFileName, + const Message_ProgressRange& theProgress) +{ + if (!Transfer(theDoc, STEPControl_AsIs, 0L, theProgress)) + return Standard_False; + return Write(theFileName.ToCString()) == IFSelect_RetDone; +} + +//======================================================================= +//function : ExternFile +//purpose : +//======================================================================= +Standard_Boolean STEPCAFControl_Writer::ExternFile(const TDF_Label& theLabel, + Handle(STEPCAFControl_ExternFile)& theExtFile) const +{ + theExtFile.Nullify(); + if (!myLabEF.IsBound(theLabel)) + return Standard_False; + theExtFile = myLabEF.Find(theLabel); + return Standard_True; +} + +//======================================================================= +//function : ExternFile +//purpose : +//======================================================================= +Standard_Boolean STEPCAFControl_Writer::ExternFile(const Standard_CString theName, + Handle(STEPCAFControl_ExternFile)& theExtFile) const +{ + theExtFile.Nullify(); + if (!myFiles.IsEmpty() || !myFiles.IsBound(theName)) + return Standard_False; + theExtFile = myFiles.Find(theName); + return Standard_True; +} + +//======================================================================= +//function : Transfer +//purpose : +//======================================================================= +Standard_Boolean STEPCAFControl_Writer::transfer(STEPControl_Writer& theWriter, + const TDF_LabelSequence& theLabels, + const STEPControl_StepModelType theMode, + const Standard_CString theIsMulti, + const Standard_Boolean theIsExternFile, + const Message_ProgressRange& theProgress) +{ + if (theLabels.IsEmpty()) + return Standard_False; + + Handle(STEPCAFControl_ActorWrite) anActor = + Handle(STEPCAFControl_ActorWrite)::DownCast(theWriter.WS()->NormAdaptor()->ActorWrite()); + + const Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(theWriter.WS()->Model()); + prepareUnit(theLabels.First(), aModel); // set local length unit to the model // translate free top-level shapes of the DECAF document - Standard_Integer ap = Interface_Static::IVal ("write.step.schema"); - TDF_LabelSequence sublabels; - Message_ProgressScope aPS(theProgress, "Labels", labels.Length()); - for ( Standard_Integer i=1; i <= labels.Length() && aPS.More(); i++) + const Standard_Integer aStepSchema = Interface_Static::IVal("write.step.schema"); + TDF_LabelSequence aSubLabels; + Message_ProgressScope aPS(theProgress, "Labels", theLabels.Length()); + // Iterate on requested shapes + for (TDF_LabelSequence::Iterator aLabelIter(theLabels); + aLabelIter.More() && aPS.More(); aLabelIter.Next()) { Message_ProgressRange aRange = aPS.Next(); - TDF_Label L = labels.Value(i); - if ( myLabels.IsBound ( L ) ) continue; // already processed - - TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape ( L ); - if ( shape.IsNull() ) continue; + TDF_Label aCurL = aLabelIter.Value(); + if (myLabels.IsBound(aCurL)) + continue; // already processed + TopoDS_Shape aCurShape = XCAFDoc_ShapeTool::GetShape(aCurL); + if (aCurShape.IsNull()) + continue; + TopoDS_Shape aShapeForBind = aCurShape; // write shape either as a whole, or as multifile (with extern refs) - if ( ! multi ) { - Actor->SetStdMode ( Standard_False ); + if (!theIsMulti) + { + anActor->SetStdMode(Standard_False); - TDF_LabelSequence comp; + TDF_LabelSequence aCompLabels; //For case when only part of assembly structure should be written in the document //if specified label is component of the assembly then @@ -569,178 +545,180 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer, //For that compound containing only specified component is binded to the label of the high-level assembly. //The such way full structure of high-level assembly was replaced on the assembly containing one component. //For case when free shape reference is (located root) also create an auxiliary assembly. - if ( XCAFDoc_ShapeTool::IsReference ( L ) ) + if (XCAFDoc_ShapeTool::IsReference(aCurL)) { TopoDS_Compound aComp; BRep_Builder aB; aB.MakeCompound(aComp); - aB.Add(aComp, shape); - shape = aComp; - comp.Append(L); - TDF_Label ref; - if ( XCAFDoc_ShapeTool::GetReferredShape ( L, ref ) ) + aB.Add(aComp, aCurShape); + aCurShape = aComp; + myPureRefLabels.Bind(aCurL, aComp); + aCompLabels.Append(aCurL); + TDF_Label aRefL; + if (XCAFDoc_ShapeTool::GetReferredShape(aCurL, aRefL)) { - if(XCAFDoc_ShapeTool::IsAssembly ( ref)) - XCAFDoc_ShapeTool::GetComponents ( ref, comp, Standard_True ); + if (XCAFDoc_ShapeTool::IsAssembly(aRefL)) + XCAFDoc_ShapeTool::GetComponents(aRefL, aCompLabels, Standard_True); } - if ( !XCAFDoc_ShapeTool::IsFree ( L ) ) - L = L.Father(); + if (!XCAFDoc_ShapeTool::IsFree(aCurL)) + aCurL = aCurL.Father(); } else { // fill sequence of (sub) shapes for which attributes should be written // and set actor to handle assemblies in a proper way - if(XCAFDoc_ShapeTool::IsAssembly ( L )) - XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_True ); + if (XCAFDoc_ShapeTool::IsAssembly(aCurL)) + XCAFDoc_ShapeTool::GetComponents(aCurL, aCompLabels, Standard_True); } - - for ( Standard_Integer k=1; k <= comp.Length(); k++ ) { - TDF_Label ref; - if ( ! XCAFDoc_ShapeTool::GetReferredShape ( comp(k), ref ) ) continue; - if ( ! myLabels.IsBound ( ref ) ) { - TopoDS_Shape refS = XCAFDoc_ShapeTool::GetShape ( ref ); - myLabels.Bind ( ref, refS ); - sublabels.Append ( ref ); - if ( XCAFDoc_ShapeTool::IsAssembly ( ref ) ) - Actor->RegisterAssembly ( refS ); + + for (TDF_LabelSequence::Iterator aCompIter(aCompLabels); aCompIter.More(); aCompIter.Next()) + { + const TDF_Label aCurSubShL = aCompIter.Value(); + if (myLabels.IsBound(aCurSubShL)) + { + continue; + } + const TopoDS_Shape aCurSh = XCAFDoc_ShapeTool::GetShape(aCurSubShL); + if (aCurSh.IsNull()) + { + continue; + } + myLabels.Bind(aCurSubShL, aCurSh); + aSubLabels.Append(aCurSubShL); + TDF_Label aRefL; + if (!XCAFDoc_ShapeTool::GetReferredShape(aCurSubShL, aRefL)) + { + continue; + } + if (!myLabels.IsBound(aRefL)) + { + TopoDS_Shape aRefSh = XCAFDoc_ShapeTool::GetShape(aRefL); + myLabels.Bind(aRefL, aRefSh); + aSubLabels.Append(aRefL); + if (XCAFDoc_ShapeTool::IsAssembly(aRefL)) + { + anActor->RegisterAssembly(aRefSh); + } } } - myLabels.Bind ( L, shape ); - sublabels.Append ( L ); + myLabels.Bind(aCurL, aShapeForBind); + aSubLabels.Append(aCurL); - if ( XCAFDoc_ShapeTool::IsAssembly ( L ) || XCAFDoc_ShapeTool::IsReference ( L ) ) - Actor->RegisterAssembly ( shape ); + if (XCAFDoc_ShapeTool::IsAssembly(aCurL) || XCAFDoc_ShapeTool::IsReference(aCurL)) + anActor->RegisterAssembly(aCurShape); - writer.Transfer(shape, mode, Standard_False, aRange); - Actor->SetStdMode ( Standard_True ); // restore default behaviour + theWriter.Transfer(aCurShape, theMode, Standard_False, aRange); + anActor->SetStdMode(Standard_True); // restore default behaviour } - else { + else + { // translate final solids - Message_ProgressScope aPS1 (aRange, NULL, 2); - TopoDS_Shape Sass = TransferExternFiles(L, mode, sublabels, multi, aPS1.Next()); + Message_ProgressScope aPS1(aRange, NULL, 2); + TopoDS_Shape aSass = transferExternFiles(aCurL, theMode, aSubLabels, theIsMulti, aPS1.Next()); if (aPS1.UserBreak()) return Standard_False; - // translate main assembly structure -/* - if ( ap == 3 ) { // if AP203, switch to AP214 - Interface_Static::SetCVal ("write.step.schema", "AP214DIS"); - Handle(StepData_StepModel) model = - Handle(StepData_StepModel)::DownCast ( writer.WS()->Model() ); - if ( model->HasHeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ) { - Handle(HeaderSection_FileSchema) fs = - Handle(HeaderSection_FileSchema)::DownCast ( model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ); - Handle(TCollection_HAsciiString) str = fs->SchemaIdentifiersValue ( 1 ); - Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "AUTOMOTIVE_DESIGN" ); - if ( str->Search ( ap214 ) <0 ) { - str->Clear(); - str->AssignCat ( ap214 ); - } - } - } -*/ - Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly"); - Interface_Static::SetCVal ("write.step.assembly", "On"); - writer.Transfer ( Sass, STEPControl_AsIs, Standard_True, aPS1.Next()); - Interface_Static::SetIVal ("write.step.assembly", assemblymode); - Interface_Static::SetIVal ("write.step.schema", ap); + Standard_Integer assemblymode = Interface_Static::IVal("write.step.assembly"); + Interface_Static::SetCVal("write.step.assembly", "On"); + theWriter.Transfer(aSass, STEPControl_AsIs, Standard_True, aPS1.Next()); + Interface_Static::SetIVal("write.step.assembly", assemblymode); } } if (aPS.UserBreak()) return Standard_False; - writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use - // writer.Transfer() without compute graph + theWriter.WS()->ComputeGraph(Standard_True); // Setting to clear and regenerate graph // write names - if ( GetNameMode() ) - WriteNames ( writer.WS(), sublabels ); + if (GetNameMode()) + writeNames(theWriter.WS(), aSubLabels); - if ( !multi ) { + if (!theIsMulti) + { // write colors - if ( GetColorMode() ) - WriteColors ( writer.WS(), sublabels ); - + if (GetColorMode()) + writeColors(theWriter.WS(), aSubLabels); + // write layers - if ( GetLayerMode() ) - WriteLayers ( writer.WS(), sublabels ); + if (GetLayerMode()) + writeLayers(theWriter.WS(), aSubLabels); // write SHUO entities - if ( GetSHUOMode() && !isExternFile ) + if (GetSHUOMode() && !theIsExternFile) // do not store SHUO for extern reference for the moment - WriteSHUOs ( writer.WS(), sublabels ); - + writeSHUOs(theWriter.WS(), aSubLabels); + // write G&DTs - if(GetDimTolMode()) { - if (ap == 5) { - WriteDGTsAP242(writer.WS(), sublabels); + if (GetDimTolMode()) + { + if (aStepSchema == 5) + { + writeDGTsAP242(theWriter.WS(), aSubLabels); } - else { - WriteDGTs(writer.WS(), sublabels); + else + { + writeDGTs(theWriter.WS(), aSubLabels); } } // write Materials - if(GetMaterialMode()) - WriteMaterials(writer.WS(),sublabels); + if (GetMaterialMode()) + writeMaterials(theWriter.WS(), aSubLabels); // register all MDGPRs in model - MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR); - for (; anItr.More(); anItr.Next()) - aModel->AddWithRefs( anItr.Value() ); + for (MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR); + anItr.More(); anItr.Next()) + { + aModel->AddWithRefs(anItr.Value()); + } } - - if ( multi ) { // external refs - WriteExternRefs ( writer.WS(), sublabels ); + + if (theIsMulti) + { // external refs + writeExternRefs(theWriter.WS(), aSubLabels); } // write validation props -// if ( multi && ap ==3 ) { -// Interface_Static::SetCVal ("write.step.schema", "AP214DIS"); -// } - if ( GetPropsMode() ) - WriteValProps ( writer.WS(), sublabels, multi ); - - Interface_Static::SetIVal ("write.step.schema", ap); + if (GetPropsMode()) + writeValProps(theWriter.WS(), aSubLabels, theIsMulti); // refresh graph - writer.WS()->ComputeGraph ( Standard_True ); - - /* ================================ - * Write names for the sub-shapes - * ================================ */ + theWriter.WS()->ComputeGraph(Standard_True); + // Write names for the sub-shapes if (Interface_Static::IVal("write.stepcaf.subshapes.name") != 0) { - const Handle(XSControl_TransferWriter) &TW = this->ChangeWriter().WS()->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); + const Handle(XSControl_TransferWriter)& TW = this->ChangeWriter().WS()->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = TW->FinderProcess(); - for ( int i = 1; i <= sublabels.Length(); i++ ) + // Iterate on requested sub shapes + for (TDF_LabelSequence::Iterator aLabelIter(aSubLabels); + aLabelIter.More(); aLabelIter.Next()) { - TDF_Label L = sublabels.Value(i); + const TDF_Label& aCurL = aLabelIter.Value(); - for ( TDF_ChildIterator it(L, Standard_True); it.More(); it.Next() ) + for (TDF_ChildIterator aChildIter(aCurL, Standard_True); aChildIter.More(); aChildIter.Next()) { - TDF_Label SubL = it.Value(); + const TDF_Label& aSubL = aChildIter.Value(); // Access name recorded in OCAF TDataStd_Name attribute - Handle(TCollection_HAsciiString) hSubName = new TCollection_HAsciiString; - if ( !GetLabelName(SubL, hSubName) ) + Handle(TCollection_HAsciiString) aHSubName = new TCollection_HAsciiString; + if (!GetLabelName(aSubL, aHSubName)) continue; // Access topological data - TopoDS_Shape SubS = XCAFDoc_ShapeTool::GetShape(SubL); - if ( SubS.IsNull() ) + TopoDS_Shape aSubS = XCAFDoc_ShapeTool::GetShape(aSubL); + if (aSubS.IsNull()) continue; // Access the correspondent STEP Representation Item - Handle(StepRepr_RepresentationItem) RI; - Handle(TransferBRep_ShapeMapper) aShMapper = TransferBRep::ShapeMapper(FP, SubS); - if ( !FP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), RI) ) + Handle(StepRepr_RepresentationItem) aRI; + Handle(TransferBRep_ShapeMapper) aShMapper = TransferBRep::ShapeMapper(aFP, aSubS); + if (!aFP->FindTypedTransient(aShMapper, STANDARD_TYPE(StepRepr_RepresentationItem), aRI)) continue; // Record the name - RI->SetName(hSubName); + aRI->SetName(aHSubName); } } } @@ -748,772 +726,770 @@ Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer, return Standard_True; } - //======================================================================= -//function : TransferExternFiles +//function : transferExternFiles //purpose : //======================================================================= - -TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L, - const STEPControl_StepModelType mode, - TDF_LabelSequence &labels, - const Standard_CString prefix, - const Message_ProgressRange& theProgress) +TopoDS_Shape STEPCAFControl_Writer::transferExternFiles(const TDF_Label& theLabel, + const STEPControl_StepModelType theMode, + TDF_LabelSequence& theLabels, + const Standard_CString thePrefix, + const Message_ProgressRange& theProgress) { // if label already translated, just return the shape - if ( myLabels.IsBound ( L ) ) { - return myLabels.Find ( L ); + if (myLabels.IsBound(theLabel)) + { + return myLabels.Find(theLabel); } - TopoDS_Compound C; - BRep_Builder B; - B.MakeCompound ( C ); - //labels.Append ( L ); + TopoDS_Compound aComp; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aComp); // if not assembly, write to separate file - if ( ! XCAFDoc_ShapeTool::IsAssembly ( L ) && !XCAFDoc_ShapeTool::IsComponent ( L )) { - labels.Append ( L ); + if (!XCAFDoc_ShapeTool::IsAssembly(theLabel) && !XCAFDoc_ShapeTool::IsComponent(theLabel)) + { + theLabels.Append(theLabel); // prepare for transfer - Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession; - newWS->SelectNorm ( "STEP" ); - STEPControl_Writer sw ( newWS, Standard_True ); - TDF_LabelSequence Lseq; - Lseq.Append ( L ); + Handle(XSControl_WorkSession) aNewWS = new XSControl_WorkSession; + aNewWS->SelectNorm("STEP"); + STEPControl_Writer aStepWriter(aNewWS, Standard_True); + TDF_LabelSequence aLabelSeq; + aLabelSeq.Append(theLabel); // construct the name for extern file - Handle(TCollection_HAsciiString) basename = new TCollection_HAsciiString; - if ( prefix && prefix[0] ) basename->AssignCat ( prefix ); - GetLabelName ( L, basename ); - Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( basename ); - name->AssignCat ( ".stp" ); - if ( myFiles.IsBound( name->ToCString() ) ) { // avoid confusions - for ( Standard_Integer k=1; k < 32000; k++ ) { - name = new TCollection_HAsciiString ( basename ); - name->AssignCat ( "_" ); - name->AssignCat ( TCollection_AsciiString ( k ).ToCString() ); - name->AssignCat ( ".stp" ); - if ( ! myFiles.IsBound ( name->ToCString() ) ) break; + Handle(TCollection_HAsciiString) aBaseName = new TCollection_HAsciiString; + if (thePrefix && thePrefix[0]) aBaseName->AssignCat(thePrefix); + GetLabelName(theLabel, aBaseName); + Handle(TCollection_HAsciiString) aNewName = new TCollection_HAsciiString(aBaseName); + aNewName->AssignCat(".stp"); + if (myFiles.IsBound(aNewName->ToCString())) + { // avoid confusions + for (Standard_Integer k = 1; k < 32000; k++) + { + aNewName = new TCollection_HAsciiString(aBaseName); + aNewName->AssignCat("_"); + aNewName->AssignCat(TCollection_AsciiString(k).ToCString()); + aNewName->AssignCat(".stp"); + if (!myFiles.IsBound(aNewName->ToCString())) break; } } // translate and record extern file - Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile; - EF->SetWS ( newWS ); - EF->SetName ( name ); - EF->SetLabel ( L ); - Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly"); - Interface_Static::SetCVal ("write.step.assembly", "Off"); - const Standard_CString multi = 0; - EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True, theProgress) ); - Interface_Static::SetIVal ("write.step.assembly", assemblymode); - myLabEF.Bind ( L, EF ); - myFiles.Bind ( name->ToCString(), EF ); + Handle(STEPCAFControl_ExternFile) anExtFile = new STEPCAFControl_ExternFile; + anExtFile->SetWS(aNewWS); + anExtFile->SetName(aNewName); + anExtFile->SetLabel(theLabel); + Standard_Integer anAssemblymode = Interface_Static::IVal("write.step.assembly"); + Interface_Static::SetCVal("write.step.assembly", "Off"); + const Standard_CString anIsMulti = 0; + anExtFile->SetTransferStatus(transfer(aStepWriter, aLabelSeq, theMode, anIsMulti, Standard_True, theProgress)); + Interface_Static::SetIVal("write.step.assembly", anAssemblymode); + myLabEF.Bind(theLabel, anExtFile); + myFiles.Bind(aNewName->ToCString(), anExtFile); // return empty compound as replacement for the shape - myLabels.Bind ( L, C ); - return C; + myLabels.Bind(theLabel, aComp); + return aComp; } - TDF_LabelSequence comp; - TDF_Label aCurL = L; + TDF_LabelSequence aCompLabels; + TDF_Label aLabel = theLabel; //if specified shape is component then high-level assembly is considered //to get valid structure with location - if ( XCAFDoc_ShapeTool::IsComponent ( L ) ) + if (XCAFDoc_ShapeTool::IsComponent(theLabel)) { - comp.Append(L); - aCurL = L.Father(); + aCompLabels.Append(theLabel); + aLabel = theLabel.Father(); } // else iterate on components add create structure of empty compounds // representing the assembly - else if (XCAFDoc_ShapeTool::IsAssembly ( L )) - XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False ); + else if (XCAFDoc_ShapeTool::IsAssembly(theLabel)) + XCAFDoc_ShapeTool::GetComponents(theLabel, aCompLabels, Standard_False); - labels.Append ( aCurL ); - Message_ProgressScope aPS(theProgress, NULL, comp.Length()); - for ( Standard_Integer k=1; k <= comp.Length() && aPS.More(); k++ ) { - TDF_Label lab = comp(k); - TDF_Label ref; - if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue; - TopoDS_Shape Scomp = TransferExternFiles(ref, mode, labels, prefix, aPS.Next()); - Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) ); - B.Add ( C, Scomp ); + theLabels.Append(aLabel); + Message_ProgressScope aPS(theProgress, NULL, aCompLabels.Length()); + // Iterate on requested shapes + for (TDF_LabelSequence::Iterator aLabelIter(aCompLabels); + aLabelIter.More() && aPS.More(); aLabelIter.Next()) + { + const TDF_Label& aCurL = aLabelIter.Value(); + TDF_Label aRefL; + if (!XCAFDoc_ShapeTool::GetReferredShape(aCurL, aRefL)) + continue; + TopoDS_Shape aShComp = transferExternFiles(aRefL, theMode, theLabels, thePrefix, aPS.Next()); + aShComp.Location(XCAFDoc_ShapeTool::GetLocation(aCurL)); + aBuilder.Add(aComp, aShComp); } - myLabels.Bind ( aCurL, C ); - return C; + myLabels.Bind(aLabel, aComp); + return aComp; } - //======================================================================= -//function : WriteExternRefs +//function : writeExternRefs //purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::WriteExternRefs (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels) const +Standard_Boolean STEPCAFControl_Writer::writeExternRefs(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const { - if ( labels.Length() <=0 ) return Standard_False; + if (theLabels.IsEmpty()) + return Standard_False; - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); - STEPConstruct_ExternRefs EFTool ( WS ); - Standard_Integer schema = Interface_Static::IVal("write.step.schema"); - for ( Standard_Integer k=1; k <= labels.Length(); k++ ) { - TDF_Label lab = labels(k); - if ( XCAFDoc_ShapeTool::IsAssembly ( lab ) ) continue; // skip assemblies + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + STEPConstruct_ExternRefs anEFTool(theWS); + Standard_Integer aStepSchema = Interface_Static::IVal("write.step.schema"); + // Iterate on requested shapes + for (TDF_LabelSequence::Iterator aLabelIter(theLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLab = aLabelIter.Value(); + if (XCAFDoc_ShapeTool::IsAssembly(aLab)) continue; // skip assemblies // get extern file - Handle(STEPCAFControl_ExternFile) EF; - if ( ! ExternFile ( lab, EF ) ) continue; // should never be + Handle(STEPCAFControl_ExternFile) anExtFile; + if (!ExternFile(aLab, anExtFile)) + continue; // should never be // find SDR - if ( ! myLabels.IsBound ( lab ) ) continue; // not recorded as translated, skip - TopoDS_Shape S = myLabels.Find ( lab ); + if (!myLabels.IsBound(aLab)) + continue; // not recorded as translated, skip + TopoDS_Shape aShape = myLabels.Find(aLab); - Handle(StepShape_ShapeDefinitionRepresentation) SDR; - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S ); - if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) { -#ifdef OCCT_DEBUG - std::cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << std::endl; -#endif + Handle(StepShape_ShapeDefinitionRepresentation) aSDR; + Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper(aFP, aShape); + if (!aFP->FindTypedTransient(mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), aSDR)) + { + Message::SendTrace() << "Warning: Cannot find SDR for " << aShape.TShape()->DynamicType()->Name() << "\n"; continue; } // add extern ref - const char* format = (schema == 3 ? "STEP AP203" : "STEP AP214"); + const char* aStepFormat = (aStepSchema == 3 ? "STEP AP203" : "STEP AP214"); // try to get PD from SDR - StepRepr_RepresentedDefinition RD = SDR->Definition(); - Handle(StepRepr_PropertyDefinition) aPropDef = RD.PropertyDefinition(); - if (aPropDef.IsNull()) { -#ifdef OCCT_DEBUG - std::cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepRepr_PropertyDefinition is null for " << S.TShape()->DynamicType()->Name() << std::endl; -#endif + StepRepr_RepresentedDefinition aRD = aSDR->Definition(); + Handle(StepRepr_PropertyDefinition) aPropDef = aRD.PropertyDefinition(); + if (aPropDef.IsNull()) + { + Message::SendTrace() << "Warning: STEPCAFControl_Writer::writeExternRefs StepRepr_PropertyDefinition is null for " << aShape.TShape()->DynamicType()->Name() << "\n"; continue; } - StepRepr_CharacterizedDefinition CharDef = aPropDef->Definition(); - Handle(StepBasic_ProductDefinition) PD = CharDef.ProductDefinition(); - if (PD.IsNull()) { -#ifdef OCCT_DEBUG - std::cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepBasic_ProductDefinition is null for " << S.TShape()->DynamicType()->Name() << std::endl; -#endif + StepRepr_CharacterizedDefinition aCharDef = aPropDef->Definition(); + Handle(StepBasic_ProductDefinition) aPD = aCharDef.ProductDefinition(); + if (aPD.IsNull()) + { + Message::SendTrace() << "Warning: STEPCAFControl_Writer::writeExternRefs StepBasic_ProductDefinition is null for " << aShape.TShape()->DynamicType()->Name() << "\n"; continue; } - EFTool.AddExternRef ( EF->GetName()->ToCString(), PD, format ); + anEFTool.AddExternRef(anExtFile->GetName()->ToCString(), aPD, aStepFormat); } - EFTool.WriteExternRefs(schema); + anEFTool.WriteExternRefs(aStepSchema); return Standard_True; } - //======================================================================= //function : FindEntities //purpose : auxiliary //======================================================================= -static Standard_Integer FindEntities (const Handle(Transfer_FinderProcess) &FP, - const TopoDS_Shape &S, - TopLoc_Location &L, - TColStd_SequenceOfTransient &seqRI) +static Standard_Integer FindEntities(const Handle(Transfer_FinderProcess)& theFP, + const TopoDS_Shape& theShape, + TopLoc_Location& theLocation, + TColStd_SequenceOfTransient& theSeqRI) { - Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, S, L ); + Handle(StepRepr_RepresentationItem) anItem = STEPConstruct::FindEntity(theFP, theShape, theLocation); - if ( ! item.IsNull() ) { - seqRI.Append ( item ); + if (!anItem.IsNull()) + { + theSeqRI.Append(anItem); return 1; } - + // may be S was splited during shape processing - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S ); - Handle(Transfer_Binder) bnd = FP->Find ( mapper ); - if ( bnd.IsNull() ) return 0; - - Handle(Transfer_TransientListBinder) TransientListBinder = + Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(theFP, theShape); + Handle(Transfer_Binder) aBinder = theFP->Find(aMapper); + if (aBinder.IsNull()) + return 0; + + Handle(Transfer_TransientListBinder) aTransientListBinder = //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) ); - Handle(Transfer_TransientListBinder)::DownCast( bnd ); - Standard_Integer nres=0; - if ( TransientListBinder.IsNull() && S.ShapeType() == TopAbs_COMPOUND) + Handle(Transfer_TransientListBinder)::DownCast(aBinder); + Standard_Integer aResCount = 0; + if (aTransientListBinder.IsNull() && theShape.ShapeType() == TopAbs_COMPOUND) { - for ( TopoDS_Iterator it(S); it.More(); it.Next() ) { - Handle(StepRepr_RepresentationItem) aLocalItem = STEPConstruct::FindEntity ( FP, it.Value(), L ); - if (aLocalItem.IsNull() ) continue; - nres++; - seqRI.Append (aLocalItem); + for (TopoDS_Iterator anIter(theShape); anIter.More(); anIter.Next()) + { + Handle(StepRepr_RepresentationItem) aLocalItem = + STEPConstruct::FindEntity(theFP, anIter.Value(), theLocation); + if (aLocalItem.IsNull()) + continue; + aResCount++; + theSeqRI.Append(aLocalItem); } } - else if(!TransientListBinder.IsNull()) + else if (!aTransientListBinder.IsNull()) { - - const Standard_Integer nb = TransientListBinder->NbTransients(); - for (Standard_Integer i=1; i<=nb; i++) { - Handle(Standard_Transient) t = TransientListBinder->Transient(i); - item = Handle(StepRepr_RepresentationItem)::DownCast(t); - if ( item.IsNull() ) continue; - nres++; - seqRI.Append ( item ); + const Standard_Integer aNbTransient = aTransientListBinder->NbTransients(); + for (Standard_Integer anInd = 1; anInd <= aNbTransient; anInd++) + { + Handle(Standard_Transient) anEntity = aTransientListBinder->Transient(anInd); + anItem = Handle(StepRepr_RepresentationItem)::DownCast(anEntity); + if (anItem.IsNull()) + continue; + aResCount++; + theSeqRI.Append(anItem); } } -/* works but is obsolete: another approach - if (i<=nb) { - TopoDS_Shape comp = TransferBRep::ShapeResult(bnd); - if ( ! comp.IsNull() && comp.ShapeType() < S.ShapeType() ) { - for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) { - MakeSTEPStyles(Styles, it.Value(), settings, STEPstyle, - Map, ( hasOwn ? &style : 0 ) ); - } - } - } -*/ - return nres; + return aResCount; } - //======================================================================= //function : getStyledItem //purpose : auxiliary //======================================================================= -static Standard_Boolean getStyledItem(const TopoDS_Shape& S, - const Handle(XCAFDoc_ShapeTool)& STool, - const STEPConstruct_Styles &Styles, - Handle(StepVisual_StyledItem) &resSelItem, - const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR) +static Standard_Boolean getStyledItem(const TopoDS_Shape& theShape, + const Handle(XCAFDoc_ShapeTool)& theShapeTool, + const STEPConstruct_Styles& theStyles, + Handle(StepVisual_StyledItem)& theResSelItem, + const MoniTool_DataMapOfShapeTransient& theMapCompMDGPR) { - TDF_Label aTopShL = STool->FindShape(S, Standard_False); - TopoDS_Shape aTopLevSh = STool->GetShape( aTopShL ); - Standard_Boolean found = Standard_False; - if ( !aTopLevSh.IsNull() && myMapCompMDGPR.IsBound( aTopLevSh ) ) { - Handle(StepVisual_PresentationRepresentation) aMDGPR = - Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopLevSh ) ); - Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items(); - // search for PSA of Monifold solid - if ( !anSelItmHArr.IsNull() ) + const TDF_Label aTopShL = theShapeTool->FindShape(theShape, Standard_False); + TopoDS_Shape aTopLevSh = theShapeTool->GetShape(aTopShL); + Standard_Boolean anIsFound = Standard_False; + if (aTopLevSh.IsNull() || !theMapCompMDGPR.IsBound(aTopLevSh)) + { + return Standard_False; + } + Handle(StepVisual_PresentationRepresentation) aMDGPR = + Handle(StepVisual_PresentationRepresentation)::DownCast(theMapCompMDGPR.Find(aTopLevSh)); + Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items(); + if (anSelItmHArr.IsNull()) + { + return Standard_False; + } + // Search for PSA of Manifold solid + TColStd_SequenceOfTransient aNewSeqRI; + Standard_Boolean isFilled = Standard_False; + for (StepRepr_HArray1OfRepresentationItem::Iterator anIter(anSelItmHArr->Array1()); + anIter.More() && !anIsFound; anIter.Next()) + { + const Handle(StepVisual_StyledItem)& aSelItm = + Handle(StepVisual_StyledItem)::DownCast(anIter.Value()); + + if (aSelItm.IsNull()) { - TColStd_SequenceOfTransient aNewseqRI; - Standard_Boolean isFilled = Standard_False; - for (Standard_Integer si = 1; si <= anSelItmHArr->Length() && !found; si++) { - Handle(StepVisual_StyledItem) aSelItm = - Handle(StepVisual_StyledItem)::DownCast(anSelItmHArr->Value(si)); - - if ( aSelItm.IsNull() ) - continue; - - // check that it is a stiled item for monifold solid brep - if (!isFilled) + continue; + } + // Check that it is a styled item for manifold solid brep + if (!isFilled) + { + TopLoc_Location aLoc; + FindEntities(theStyles.FinderProcess(), aTopLevSh, aLoc, aNewSeqRI); + isFilled = Standard_True; + } + if (!aNewSeqRI.IsEmpty()) + { + const Handle(StepRepr_RepresentationItem)& anItem = aSelItm->Item(); + Standard_Boolean isSameMonSolBR = Standard_False; + for (TColStd_SequenceOfTransient::Iterator aIterRI(aNewSeqRI); + aIterRI.More(); aIterRI.Next()) + { + if (!anItem.IsNull() && anItem == aIterRI.Value()) { - TopLoc_Location Loc; - FindEntities(Styles.FinderProcess(), aTopLevSh, Loc, aNewseqRI); - isFilled = Standard_True; - } - if ( aNewseqRI.Length() > 0 ) - { - - const Handle(StepRepr_RepresentationItem)& anItem = aSelItm->Item(); - Standard_Boolean isSameMonSolBR = Standard_False; - for (Standard_Integer mi = 1; mi <= aNewseqRI.Length(); mi++) { - if ( !anItem.IsNull() && anItem == aNewseqRI.Value( mi ) ) { - isSameMonSolBR = Standard_True; - break; - } - } - if (!isSameMonSolBR) - continue; - } - - - for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) { - const Handle(StepVisual_PresentationStyleAssignment)& aFatherPSA = aSelItm->StylesValue(jsi); - // check for PSA for top-level (not Presentation style by context for NAUO) - if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext))) - continue; - resSelItem = aSelItm; - found = Standard_True; + isSameMonSolBR = Standard_True; + break; } } + if (!isSameMonSolBR) + continue; + } + for (StepVisual_HArray1OfPresentationStyleAssignment::Iterator aStyleIter(aSelItm->Styles()->Array1()); + aStyleIter.More() && !anIsFound; aStyleIter.Next()) + { + const Handle(StepVisual_PresentationStyleAssignment)& aFatherPSA = aStyleIter.Value(); + // check for PSA for top-level (not Presentation style by context for NAUO) + if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext))) + continue; + theResSelItem = aSelItm; + anIsFound = Standard_True; } } - return found; + return anIsFound; } - //======================================================================= //function : setDefaultInstanceColor //purpose : auxiliary //======================================================================= -static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledItem) &aSelItm, - Handle(StepVisual_PresentationStyleAssignment)& PSA) +static Standard_Boolean setDefaultInstanceColor(const Handle(StepVisual_StyledItem)& theStyleItem, + Handle(StepVisual_PresentationStyleAssignment)& thePSA) { - Standard_Boolean found = Standard_False; - for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) { - Handle(StepVisual_PresentationStyleAssignment) aFatherPSA = aSelItm->StylesValue(jsi); - // check for PSA for top-level (not Presentation style by context for NAUO) - if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext))) - return Standard_False; - - // get style select from father PSA - if (aFatherPSA->NbStyles() > 0) { - Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles = - new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles()); - for (Standard_Integer k = 1; k <= aFatherPSA->NbStyles(); k++) { - StepVisual_PresentationStyleSelect PSS; - StepVisual_PresentationStyleSelect olDPSS = aFatherPSA->StylesValue(k); - if (!olDPSS.PointStyle().IsNull()) - PSS.SetValue (olDPSS.PointStyle()); - else if (!olDPSS.CurveStyle().IsNull()) - PSS.SetValue (olDPSS.CurveStyle()); - else if (!olDPSS.SurfaceStyleUsage().IsNull()) - PSS.SetValue (olDPSS.SurfaceStyleUsage()); - else { - found = Standard_False; - break; - } - //aFatherStyles->SetValue( k, PSS ); - aFatherStyles->SetValue( k, olDPSS ); - found = Standard_True; - } - // init PSA of NAUO - if (found) { - PSA->Init( aFatherStyles ); - } - } - - } - return found; -} + Standard_Boolean anIsFound = Standard_False; + for (StepVisual_HArray1OfPresentationStyleAssignment::Iterator aStyleIter(theStyleItem->Styles()->Array1()); + aStyleIter.More() && !anIsFound; aStyleIter.Next()) + { + const Handle(StepVisual_PresentationStyleAssignment)& aFatherPSA = aStyleIter.Value(); + // check for PSA for top-level (not Presentation style by context for NAUO) + if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext))) + return Standard_False; + // get style select from father PSA + if (aFatherPSA->NbStyles() > 0) + { + Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles = + new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles()); + Standard_Integer aSettingInd = 1; + for (StepVisual_HArray1OfPresentationStyleSelect::Iterator aFatherStyleIter(aFatherPSA->Styles()->Array1()); + aFatherStyleIter.More(); aFatherStyleIter.Next()) + { + StepVisual_PresentationStyleSelect aPSS; + StepVisual_PresentationStyleSelect anOlDPSS = aFatherStyleIter.Value(); + if (!anOlDPSS.PointStyle().IsNull()) + aPSS.SetValue(anOlDPSS.PointStyle()); + else if (!anOlDPSS.CurveStyle().IsNull()) + aPSS.SetValue(anOlDPSS.CurveStyle()); + else if (!anOlDPSS.SurfaceStyleUsage().IsNull()) + aPSS.SetValue(anOlDPSS.SurfaceStyleUsage()); + else + { + anIsFound = Standard_False; + break; + } + aFatherStyles->SetValue(aSettingInd++, anOlDPSS); + anIsFound = Standard_True; + } + // init PSA of NAUO + if (anIsFound) + { + thePSA->Init(aFatherStyles); + } + } + } + return anIsFound; +} //======================================================================= //function : MakeSTEPStyles //purpose : auxiliary //======================================================================= -static void MakeSTEPStyles (STEPConstruct_Styles &Styles, - const TopoDS_Shape &S, - const XCAFPrs_IndexedDataMapOfShapeStyle &settings, - Handle(StepVisual_StyledItem) &override, - TopTools_MapOfShape &Map, - const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR, - STEPConstruct_DataMapOfAsciiStringTransient &DPDCs, - STEPConstruct_DataMapOfPointTransient &ColRGBs, - const Handle(XCAFDoc_ColorTool)& CTool, - const XCAFPrs_Style *inherit = 0, - const Standard_Boolean isComponent = Standard_False) +static void MakeSTEPStyles(STEPConstruct_Styles& theStyles, + const TopoDS_Shape& theShape, + const XCAFPrs_IndexedDataMapOfShapeStyle& theSettings, + Handle(StepVisual_StyledItem)& theOverride, + TopTools_MapOfShape& theMap, + const MoniTool_DataMapOfShapeTransient& theMapCompMDGPR, + STEPConstruct_DataMapOfAsciiStringTransient& theDPDCs, + STEPConstruct_DataMapOfPointTransient& theColRGBs, + const Handle(XCAFDoc_ShapeTool)& theShTool, + const XCAFPrs_Style* theInherit = 0, + const Standard_Boolean theIsComponent = Standard_False) { // skip already processed shapes - if ( ! Map.Add ( S ) ) return; + if (!theMap.Add(theShape)) + return; // check if shape has its own style (r inherits from ancestor) - XCAFPrs_Style style; - if ( inherit ) style = *inherit; - if ( settings.Contains(S) ) { - XCAFPrs_Style own = settings.FindFromKey(S); - if ( !own.IsVisible() ) style.SetVisibility ( Standard_False ); - if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() ); - if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurfRGBA() ); + XCAFPrs_Style aStyle; + if (theInherit) aStyle = *theInherit; + if (theSettings.Contains(theShape)) + { + XCAFPrs_Style anOwnStyle = theSettings.FindFromKey(theShape); + if (!anOwnStyle.IsVisible()) + aStyle.SetVisibility(Standard_False); + if (anOwnStyle.IsSetColorCurv()) + aStyle.SetColorCurv(anOwnStyle.GetColorCurv()); + if (anOwnStyle.IsSetColorSurf()) + aStyle.SetColorSurf(anOwnStyle.GetColorSurfRGBA()); } // translate colors to STEP - Handle(StepVisual_Colour) surfColor, curvColor; - Standard_Real RenderTransp = 0.0; - if ( style.IsSetColorSurf() ) { - Quantity_ColorRGBA sCol = style.GetColorSurfRGBA(); - RenderTransp = 1.0 - sCol.Alpha(); - surfColor = Styles.EncodeColor(sCol.GetRGB(),DPDCs,ColRGBs); + Handle(StepVisual_Colour) aSurfColor, aCurvColor; + Standard_Real aRenderTransp = 0.0; + if (aStyle.IsSetColorSurf()) + { + Quantity_ColorRGBA aSurfCol = aStyle.GetColorSurfRGBA(); + aRenderTransp = 1.0 - aSurfCol.Alpha(); + aSurfColor = theStyles.EncodeColor(aSurfCol.GetRGB(), theDPDCs, theColRGBs); } - if ( style.IsSetColorCurv() ) - curvColor = Styles.EncodeColor(style.GetColorCurv(),DPDCs,ColRGBs); - - Standard_Boolean hasOwn = ( ! surfColor.IsNull() || - ! curvColor.IsNull() || - ! style.IsVisible() ); + if (aStyle.IsSetColorCurv()) + aCurvColor = theStyles.EncodeColor(aStyle.GetColorCurv(), theDPDCs, theColRGBs); + + Standard_Boolean aHasOwn = (!aSurfColor.IsNull() || + !aCurvColor.IsNull() || + !aStyle.IsVisible()); // find target item and assign style to it - Handle(StepVisual_StyledItem) STEPstyle = override; - if ( hasOwn ) { - if ( S.ShapeType() != TopAbs_COMPOUND || isComponent ) { // skip compounds, let subshapes inherit its colors - TopLoc_Location L; - TColStd_SequenceOfTransient seqRI; - Standard_Integer nb = FindEntities ( Styles.FinderProcess(), S, L, seqRI ); -#ifdef OCCT_DEBUG - if ( nb <=0 ) std::cout << "Warning: Cannot find RI for " << S.TShape()->DynamicType()->Name() << std::endl; -#endif + Handle(StepVisual_StyledItem) aSTEPstyle = theOverride; + if (aHasOwn) + { + if (theShape.ShapeType() != TopAbs_COMPOUND || theIsComponent) + { // skip compounds, let subshapes inherit its colors + TopLoc_Location aLocation; + TColStd_SequenceOfTransient aSeqRI; + Standard_Integer aNbEntities = FindEntities(theStyles.FinderProcess(), theShape, aLocation, aSeqRI); + if (aNbEntities <= 0) + Message::SendTrace() << "Warning: Cannot find RI for " << theShape.TShape()->DynamicType()->Name() << "\n"; //Get overridden style gka 10.06.03 - if ( isComponent && nb) - getStyledItem(S, CTool->ShapeTool(), Styles, override,myMapCompMDGPR); - - - for ( Standard_Integer i=1; i <= nb; i++ ) { - Handle(StepRepr_RepresentationItem) item = - Handle(StepRepr_RepresentationItem)::DownCast(seqRI(i)); - Handle(StepVisual_PresentationStyleAssignment) PSA; - if ( style.IsVisible() || !surfColor.IsNull() || !curvColor.IsNull() ) { - PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, surfColor, RenderTransp, isComponent ); + if (theIsComponent && aNbEntities > 0) + getStyledItem(theShape, theShTool, theStyles, theOverride, theMapCompMDGPR); + + for (TColStd_SequenceOfTransient::Iterator anEntIter(aSeqRI); + anEntIter.More(); anEntIter.Next()) + { + const Handle(StepRepr_RepresentationItem)& anItem = + Handle(StepRepr_RepresentationItem)::DownCast(anEntIter.Value()); + Handle(StepVisual_PresentationStyleAssignment) aPSA; + if (aStyle.IsVisible() || !aSurfColor.IsNull() || !aCurvColor.IsNull()) + { + aPSA = theStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aSurfColor, aRenderTransp, theIsComponent); } - else { + else + { // default white color - surfColor = Styles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE),DPDCs,ColRGBs); - PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, surfColor, 0.0, isComponent ); - if ( isComponent ) - setDefaultInstanceColor( override, PSA); - + aSurfColor = theStyles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE), theDPDCs, theColRGBs); + aPSA = theStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aSurfColor, 0.0, theIsComponent); + if (theIsComponent) + setDefaultInstanceColor(theOverride, aPSA); + } // end of component case - - STEPstyle = Styles.AddStyle ( item, PSA, override ); - hasOwn = Standard_False; + + aSTEPstyle = theStyles.AddStyle(anItem, aPSA, theOverride); + aHasOwn = Standard_False; } } } // iterate on subshapes (except vertices :) - if ( S.ShapeType() == TopAbs_EDGE ) return; - if ( !isComponent ) // PTV 10.02.2003 - for ( TopoDS_Iterator it(S); it.More(); it.Next() ) { - MakeSTEPStyles ( Styles, it.Value(), settings, STEPstyle, - Map, myMapCompMDGPR, DPDCs, ColRGBs, CTool, - ( hasOwn ? &style : 0 ) ); - } + if (theShape.ShapeType() == TopAbs_EDGE) + return; + if (theIsComponent) + { + return; + } + for (TopoDS_Iterator anIter(theShape); anIter.More(); anIter.Next()) + { + MakeSTEPStyles(theStyles, anIter.Value(), theSettings, aSTEPstyle, + theMap, theMapCompMDGPR, theDPDCs, theColRGBs, theShTool, + (aHasOwn ? &aStyle : 0)); + } } -/* -static Standard_Boolean getFatherColor (const TDF_Label& L, - const Handle(XCAFDoc_ColorTool)& CTool, - XCAFPrs_Style& style) -{ - Standard_Boolean done = Standard_False; - TopoDS_Shape aSh = CTool->ShapeTool()->GetShape( L ); - TDF_Label aFL = CTool->ShapeTool()->FindShape( aSh ); - if (aFL.IsNull() || aFL == L) - return done; - Quantity_Color C; - if ( CTool->GetColor ( aFL, XCAFDoc_ColorGen, C ) ) { - style.SetColorCurv ( C ); - style.SetColorSurf ( C ); - done = Standard_True; - } - if ( CTool->GetColor ( aFL, XCAFDoc_ColorSurf, C ) ) { - style.SetColorSurf ( C ); - done = Standard_True; - } - if ( CTool->GetColor ( aFL, XCAFDoc_ColorCurv, C ) ) { - style.SetColorCurv ( C ); - done = Standard_True; - } - - return done; -} -*/ - - //======================================================================= -//function : WriteColors -//purpose : +//function : writeColors +//purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels) +Standard_Boolean STEPCAFControl_Writer::writeColors(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) { - if ( labels.Length() <=0 ) return Standard_False; + if (theLabels.IsEmpty()) + return Standard_False; - // Iterate on shapes in the document - Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) ); - Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool( labels(1) ); - if ( CTool.IsNull() ) return Standard_False; - - STEPConstruct_Styles Styles ( WS ); + STEPConstruct_Styles Styles(theWS); STEPConstruct_DataMapOfAsciiStringTransient DPDCs; STEPConstruct_DataMapOfPointTransient ColRGBs; - for ( Standard_Integer i=1; i <= labels.Length(); i++ ) { - TDF_Label L = labels.Value(i); - - Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) ); + // Iterate on requested shapes + for (TDF_LabelSequence::Iterator aLabelIter(theLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label aLabel = aLabelIter.Value(); + // Iterate on shapes in the document + Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(aLabel); // Skip assemblies: colors assigned to assemblies and their instances // are not supported (it is not clear how to encode that in STEP) - if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) { -#ifdef OCCT_DEBUG - std::cout << "Warning: Cannot write color for Assembly" << std::endl; - std::cout << "Info: Check for colors assigned to components in assembly" << std::endl; -#endif + if (XCAFDoc_ShapeTool::IsAssembly(aLabel)) + { + Message::SendTrace() << "Warning: Cannot write color for Assembly" << "\n"; + Message::SendTrace() << "Info: Check for colors assigned to components in assembly" << "\n"; // PTV 22.01.2003 Write color for instances. TDF_LabelSequence compLabels; - if ( aSTool.IsNull() ) + if (!aSTool->GetComponents(aLabel, compLabels)) continue; - if (!aSTool->GetComponents(L, compLabels)) - continue; - WriteColors(WS, compLabels); + writeColors(theWS, compLabels); continue; } Styles.ClearStyles(); // get a target shape and try to find corresponding context // (all the colors set under that label will be put into that context) - TopoDS_Shape S; - if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue; - Standard_Boolean isComponent = aSTool->IsComponent( L ); - TopoDS_Shape aTopSh = S; - Handle(StepRepr_RepresentationContext) Context = Styles.FindContext ( S ); - if ( isComponent ) { - TDF_Label aTopShL = aSTool->FindShape(S, Standard_False); + TopoDS_Shape aShape; + if (!XCAFDoc_ShapeTool::GetShape(aLabel, aShape)) + continue; + Standard_Boolean anIsComponent = aSTool->IsComponent(aLabel) || myPureRefLabels.IsBound(aLabel); + TopoDS_Shape aTopSh = aShape; + Handle(StepRepr_RepresentationContext) aContext = Styles.FindContext(aShape); + if (anIsComponent) + { + TDF_Label aTopShL = aSTool->FindShape(aShape, Standard_False); if (aTopShL.IsNull()) continue; - aTopSh = aSTool->GetShape( aTopShL ); - Context = Styles.FindContext ( aTopSh ); + aTopSh = aSTool->GetShape(aTopShL); + aContext = Styles.FindContext(aTopSh); } - if ( Context.IsNull() ) - continue; - + if (aContext.IsNull()) + continue; + // collect settings set on that label - XCAFPrs_IndexedDataMapOfShapeStyle settings; - TDF_LabelSequence seq; - seq.Append ( L ); - XCAFDoc_ShapeTool::GetSubShapes ( L, seq ); - Standard_Boolean isVisible = Standard_True; - for ( Standard_Integer j = 1; j <= seq.Length(); j++ ) { - TDF_Label lab = seq.Value(j); - XCAFPrs_Style style; - Quantity_ColorRGBA C; - if ( lab == L ) { + XCAFPrs_IndexedDataMapOfShapeStyle aSettings; + TDF_LabelSequence aSeq; + aSeq.Append(aLabel); + XCAFDoc_ShapeTool::GetSubShapes(aLabel, aSeq); + Standard_Boolean anIsVisible = Standard_True; + for (TDF_LabelSequence::Iterator aSeqIter(aSeq); + aSeqIter.More(); aSeqIter.Next()) + { + const TDF_Label& aSeqValue = aSeqIter.Value(); + XCAFPrs_Style aStyle; + Quantity_ColorRGBA aColor; + if (aSeqValue == aLabel) + { // check for invisible status of object on label - if ( !CTool->IsVisible( lab ) ) { - isVisible = Standard_False; - style.SetVisibility( Standard_False ); + if (!XCAFDoc_ColorTool::IsVisible(aSeqValue)) + { + anIsVisible = Standard_False; + aStyle.SetVisibility(Standard_False); } } - if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) { - style.SetColorCurv ( C.GetRGB() ); - style.SetColorSurf ( C ); - } - if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) ) - style.SetColorSurf ( C ); - if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) ) - style.SetColorCurv ( C.GetRGB() ); - if (!style.IsSetColorSurf()) + if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorGen, aColor)) { - Handle(XCAFDoc_VisMaterial) aVisMat = aMatTool->GetShapeMaterial (lab); - if (!aVisMat.IsNull() - && !aVisMat->IsEmpty()) + aStyle.SetColorCurv(aColor.GetRGB()); + aStyle.SetColorSurf(aColor); + } + if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorSurf, aColor)) + aStyle.SetColorSurf(aColor); + if (XCAFDoc_ColorTool::GetColor(aSeqValue, XCAFDoc_ColorCurv, aColor)) + aStyle.SetColorCurv(aColor.GetRGB()); + if (!aStyle.IsSetColorSurf()) + { + Handle(XCAFDoc_VisMaterial) aVisMat = XCAFDoc_VisMaterialTool::GetShapeMaterial(aSeqValue); + if (!aVisMat.IsNull() && !aVisMat->IsEmpty()) { // only color can be stored in STEP - style.SetColorSurf (aVisMat->BaseColor()); + aStyle.SetColorSurf(aVisMat->BaseColor()); } } - - // commented, cause we are need to take reference from -// if ( isComponent && lab == L && !isVisible) -// if ( !style.IsSetColorSurf() && !style.IsSetColorCurv() ) { -// getFatherColor ( L, CTool, style); -// } - if ( ! style.IsSetColorCurv() && ! style.IsSetColorSurf() && isVisible ) continue; + if (!aStyle.IsSetColorCurv() && !aStyle.IsSetColorSurf() && anIsVisible) continue; - TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab ); - XCAFPrs_Style* aMapStyle = settings.ChangeSeek (sub); + TopoDS_Shape aSub = XCAFDoc_ShapeTool::GetShape(aSeqValue); + XCAFPrs_Style* aMapStyle = aSettings.ChangeSeek(aSub); if (aMapStyle == NULL) - settings.Add ( sub, style ); + aSettings.Add(aSub, aStyle); else - *aMapStyle = style; + *aMapStyle = aStyle; } - - if ( settings.Extent() <=0 ) continue; + + if (aSettings.Extent() <= 0) + continue; // iterate on subshapes and create STEP styles - Handle(StepVisual_StyledItem) override; - TopTools_MapOfShape Map; - - MakeSTEPStyles(Styles,S,settings,override,Map,myMapCompMDGPR,DPDCs,ColRGBs,CTool,0,isComponent); - + Handle(StepVisual_StyledItem) anOverride; + TopTools_MapOfShape aMap; + + MakeSTEPStyles(Styles, aShape, aSettings, anOverride, + aMap, myMapCompMDGPR, DPDCs, ColRGBs, aSTool, 0, anIsComponent); + // create MDGPR and record it in model Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR; - if (!isComponent) { - if ( myMapCompMDGPR.IsBound( aTopSh )) { -#ifdef OCCT_DEBUG - std::cerr << "Error: Current Top-Level shape have MDGPR already " << std::endl; -#endif + if (!anIsComponent) + { + if (myMapCompMDGPR.IsBound(aTopSh)) + { + Message::SendTrace() << "Error: Current Top-Level shape have MDGPR already " << "\n"; } - Styles.CreateMDGPR ( Context, aMDGPR ); + Styles.CreateMDGPR(aContext, aMDGPR); if (!aMDGPR.IsNull()) - myMapCompMDGPR.Bind( aTopSh, aMDGPR ); + myMapCompMDGPR.Bind(aTopSh, aMDGPR); } - else { + else + { // create SDR and add to model. - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S ); - Handle(StepShape_ContextDependentShapeRepresentation) CDSR; - if ( FP->FindTypedTransient(mapper, - STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), - CDSR) ) { + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, aShape); + Handle(StepShape_ContextDependentShapeRepresentation) aCDSR; + if (aFP->FindTypedTransient(aMapper, + STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), + aCDSR)) + { // create SDR for NAUO - Handle(StepRepr_ProductDefinitionShape) nullPDS; // important to be NULL - Styles.CreateNAUOSRD( Context, CDSR, nullPDS ); - + Handle(StepRepr_ProductDefinitionShape) aNullPDS; // important to be NULL + Styles.CreateNAUOSRD(aContext, aCDSR, aNullPDS); + // search for MDGPR of the component top-level shape - if ( myMapCompMDGPR.IsBound( aTopSh )) { - aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) ); - } else { + if (myMapCompMDGPR.IsBound(aTopSh)) + { + aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast(myMapCompMDGPR.Find(aTopSh)); + } + else + { aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation; - Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" ); - aMDGPR->SetName( ReprName ); - aMDGPR->SetContextOfItems( Context ); - myMapCompMDGPR.Bind ( aTopSh, aMDGPR ); + Handle(TCollection_HAsciiString) aReprName = new TCollection_HAsciiString(""); + aMDGPR->SetName(aReprName); + aMDGPR->SetContextOfItems(aContext); + myMapCompMDGPR.Bind(aTopSh, aMDGPR); } - Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items(); + Handle(StepRepr_HArray1OfRepresentationItem) anOldItems = aMDGPR->Items(); Standard_Integer oldLengthlen = 0; - if (!oldItems.IsNull()) - oldLengthlen = oldItems->Length(); - const Standard_Integer nbIt = oldLengthlen + Styles.NbStyles(); - if(!nbIt) + if (!anOldItems.IsNull()) + oldLengthlen = anOldItems->Length(); + const Standard_Integer aNbIt = oldLengthlen + Styles.NbStyles(); + if (!aNbIt) continue; - Handle(StepRepr_HArray1OfRepresentationItem) newItems = - new StepRepr_HArray1OfRepresentationItem(1, nbIt); - Standard_Integer si; - Standard_Integer el = 1; - for ( si=1; si <= oldLengthlen; si++ ) - newItems->SetValue( el++, oldItems->Value( si ) ); - for ( si=1; si <= Styles.NbStyles(); si++ ) { - newItems->SetValue( el++, Styles.Style(si)); + Handle(StepRepr_HArray1OfRepresentationItem) aNewItems = + new StepRepr_HArray1OfRepresentationItem(1, aNbIt); + Standard_Integer anElemInd = 1; + for (Standard_Integer aStyleInd = 1; aStyleInd <= oldLengthlen; aStyleInd++) + { + aNewItems->SetValue(anElemInd++, anOldItems->Value(aStyleInd)); } - - if (newItems->Length() > 0) - aMDGPR->SetItems( newItems ); + for (Standard_Integer aStyleInd = 1; aStyleInd <= Styles.NbStyles(); aStyleInd++) + { + aNewItems->SetValue(anElemInd++, Styles.Style(aStyleInd)); + } + + if (aNewItems->Length() > 0) + aMDGPR->SetItems(aNewItems); } //end of work with CDSR } - if ( !isVisible ) { - // create invisibility item and refer for styledItem - Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility(); - Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = - new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles()); + if (!anIsVisible) + { + // create invisibility item and refer for styledItem + Handle(StepVisual_Invisibility) anInvisibility = new StepVisual_Invisibility(); + Handle(StepVisual_HArray1OfInvisibleItem) anInvisibilitySeq = + new StepVisual_HArray1OfInvisibleItem(1, Styles.NbStyles()); // put all style item into the harray - for ( Standard_Integer si=1; si <= Styles.NbStyles(); si++ ) { - Handle(StepRepr_RepresentationItem) styledItm = Styles.Style(si); + for (Standard_Integer aStyleInd = 1; aStyleInd <= Styles.NbStyles(); aStyleInd++) + { + Handle(StepRepr_RepresentationItem) aStyledItm = Styles.Style(aStyleInd); StepVisual_InvisibleItem anInvItem; - anInvItem.SetValue( styledItm ); - HInvsblItm->SetValue( si, anInvItem ); + anInvItem.SetValue(aStyledItm); + anInvisibilitySeq->SetValue(aStyleInd, anInvItem); } // set the invisibility of items - Invsblt->Init( HInvsblItm ); - WS->Model()->AddWithRefs( Invsblt ); + anInvisibility->Init(anInvisibilitySeq); + theWS->Model()->AddWithRefs(anInvisibility); } } - return Standard_True; } - //======================================================================= -//function : WriteNames +//function : writeNames //purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels) const +Standard_Boolean STEPCAFControl_Writer::writeNames(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const { - if ( labels.Length() <=0 ) return Standard_False; + if (theLabels.IsEmpty()) + return Standard_False; // get working data - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); // Iterate on requested shapes - for ( Standard_Integer i=1; i <= labels.Length(); i++ ) { - TDF_Label L = labels.Value(i); - + for (TDF_LabelSequence::Iterator aLabelIter(theLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + // find target STEP entity for the current shape + if (!myLabels.IsBound(aLabel)) + continue; // not recorded as translated, skip // get name - Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString; - if (GetLabelName (L, hName)) + Handle(TCollection_HAsciiString) aHName = new TCollection_HAsciiString; + if (!GetLabelName(aLabel, aHName)) { - // find target STEP entity for the current shape - if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip - TopoDS_Shape S = myLabels.Find ( L ); - - Handle(StepShape_ShapeDefinitionRepresentation) SDR; - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S ); - if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) { -#ifdef OCCT_DEBUG - std::cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << std::endl; -#endif - continue; - } - - // set the name to the PRODUCT - Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition(); - if ( PropD.IsNull() ) continue; - Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition(); - if ( PD.IsNull() ) continue; - Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct(); - - Prod->SetId ( hName ); - Prod->SetName ( hName ); + continue; } - - // write names for components of assemblies - if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) { - TDF_LabelSequence seq; - XCAFDoc_ShapeTool::GetComponents ( L, seq ); - for (Standard_Integer k=1; k <= seq.Length(); k++) { - TDF_Label lab = seq(k); - - // get shape with correct location - TDF_Label Lref; - if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) || - ! myLabels.IsBound ( Lref ) ) continue; - TopoDS_Shape S = myLabels.Find ( Lref ); - S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) ); - - hName = new TCollection_HAsciiString; - if ( ! GetLabelName (lab, hName) ) continue; - - // find the target CDSR corresponding to a shape - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S ); - Handle(Transfer_Binder) binder = FP->Find ( mapper ); - Handle(StepShape_ContextDependentShapeRepresentation) CDSR; - if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) ) - continue; - Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation(); - Handle(StepBasic_ProductDefinitionRelationship) NAUO = PDS->Definition().ProductDefinitionRelationship(); - if ( ! NAUO.IsNull() ) NAUO->SetName ( hName ); + const TopoDS_Shape& aShape = myLabels.Find(aLabel); + Handle(StepShape_ShapeDefinitionRepresentation) aSDR; + Handle(StepShape_ContextDependentShapeRepresentation) aCDSR; + Standard_Boolean isComponent = XCAFDoc_ShapeTool::IsComponent(aLabel) || myPureRefLabels.IsBound(aLabel); + Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, aShape); + if (isComponent && aFP->FindTypedTransient(aMapper, STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), aCDSR)) + { + Handle(StepRepr_ProductDefinitionShape) aPDS = aCDSR->RepresentedProductRelation(); + Handle(StepBasic_ProductDefinitionRelationship) aNAUO = aPDS->Definition().ProductDefinitionRelationship(); + if (!aNAUO.IsNull()) + aNAUO->SetName(aHName); + TopoDS_Shape anInternalAssembly; + if (myPureRefLabels.Find(aLabel, anInternalAssembly)) + { + Handle(TransferBRep_ShapeMapper) aMapperOfInternalShape = TransferBRep::ShapeMapper(aFP, anInternalAssembly); + aFP->FindTypedTransient(aMapperOfInternalShape, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), aSDR); } } + if (!aSDR.IsNull() || + (aCDSR.IsNull() && aFP->FindTypedTransient(aMapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), aSDR))) + { + // set the name to the PRODUCT + Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition(); + if (aPropD.IsNull()) + continue; + Handle(StepBasic_ProductDefinition) aPD = aPropD->Definition().ProductDefinition(); + if (aPD.IsNull()) + continue; + Handle(StepBasic_Product) aProd = aPD->Formation()->OfProduct(); + + aProd->SetId(aHName); + aProd->SetName(aHName); + } + else + { + Message::SendTrace() << "Warning: Cannot find RI for " << aShape.TShape()->DynamicType()->Name() << "\n"; + continue; + } } - return Standard_True; } - //======================================================================= //function : WritePropsForLabel //purpose : //======================================================================= -static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) &WS, - const Handle(XCAFDoc_ShapeTool) &aSTool, - const STEPCAFControl_DataMapOfLabelShape &myLabels, - const TDF_Label &L, - const Standard_CString multi) +static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession)& theWS, + const STEPCAFControl_DataMapOfLabelShape& theLabels, + const TDF_Label& theLabel, + const Standard_CString theIsMulti) { - if(L.IsNull()) return Standard_False; + if (theLabel.IsNull()) + return Standard_False; - STEPConstruct_ValidationProps Props ( WS ); + STEPConstruct_ValidationProps aProps(theWS); - TopoDS_Shape S = aSTool->GetShape(L); - if(S.IsNull()) return Standard_False; + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theLabel); + if (aShape.IsNull()) + return Standard_False; - if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) { + if (!theIsMulti || XCAFDoc_ShapeTool::IsAssembly(theLabel)) + { // write area - Handle(XCAFDoc_Area) A; - L.FindAttribute ( XCAFDoc_Area::GetID(), A ); - if ( ! A.IsNull() ) { - Props.AddArea ( S, A->Get() ); + Handle(XCAFDoc_Area) anArea; + theLabel.FindAttribute(XCAFDoc_Area::GetID(), anArea); + if (!anArea.IsNull()) + { + aProps.AddArea(aShape, anArea->Get()); } // write volume - Handle(XCAFDoc_Volume) V; - L.FindAttribute ( XCAFDoc_Volume::GetID(), V ); - if ( ! V.IsNull() ) { - Props.AddVolume ( S, V->Get() ); + Handle(XCAFDoc_Volume) aVolume; + theLabel.FindAttribute(XCAFDoc_Volume::GetID(), aVolume); + if (!aVolume.IsNull()) + { + aProps.AddVolume(aShape, aVolume->Get()); } } // write centroid - Handle(XCAFDoc_Centroid) C; - L.FindAttribute ( XCAFDoc_Centroid::GetID(), C ); - if ( ! C.IsNull() ) { - Props.AddCentroid ( S, C->Get() ); + Handle(XCAFDoc_Centroid) aCentroid; + theLabel.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid); + if (!aCentroid.IsNull()) + { + aProps.AddCentroid(aShape, aCentroid->Get()); } - if( XCAFDoc_ShapeTool::IsCompound(L) || XCAFDoc_ShapeTool::IsAssembly(L) ) { - if(L.HasChild()) { - for(Standard_Integer ich=1; ich<=L.NbChildren(); ich++) { - WritePropsForLabel(WS,aSTool,myLabels,L.FindChild(ich),multi); + if (XCAFDoc_ShapeTool::IsCompound(theLabel) || XCAFDoc_ShapeTool::IsAssembly(theLabel)) + { + if (theLabel.HasChild()) + { + for (Standard_Integer aChildInd = 1; aChildInd <= theLabel.NbChildren(); aChildInd++) + { + WritePropsForLabel(theWS, theLabels, theLabel.FindChild(aChildInd), theIsMulti); } } } @@ -1521,677 +1497,674 @@ static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) & return Standard_True; } - //======================================================================= -//function : WriteValProps +//function : writeValProps //purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::WriteValProps (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels, - const Standard_CString multi) const +Standard_Boolean STEPCAFControl_Writer::writeValProps(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels, + const Standard_CString theIsMulti) const { - if ( labels.Length() <=0 ) return Standard_False; - - // get working data -// STEPConstruct_ValidationProps Props ( WS ); - Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) ); + if (theLabels.IsEmpty()) + return Standard_False; // Iterate on requested shapes - for ( Standard_Integer i=1; i <= labels.Length(); i++ ) { - TDF_Label L = labels.Value(i); + for (TDF_LabelSequence::Iterator aLabelIter(theLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); - WritePropsForLabel(WS,aSTool,myLabels,L,multi); -/* - // find target STEP entity for the current shape - if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip - TopoDS_Shape S = myLabels.Find ( L ); - - // write area and volume (except for components in multifile mode) - if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) { - Handle(XCAFDoc_Area) A; - L.FindAttribute ( XCAFDoc_Area::GetID(), A ); - if ( ! A.IsNull() ) Props.AddArea ( S, A->Get() ); - - Handle(XCAFDoc_Volume) V; - L.FindAttribute ( XCAFDoc_Volume::GetID(), V ); - if ( ! V.IsNull() ) Props.AddVolume ( S, V->Get() ); - } - - // write centroid - Handle(XCAFDoc_Centroid) C; - L.FindAttribute ( XCAFDoc_Centroid::GetID(), C ); - if ( ! C.IsNull() ) Props.AddCentroid ( S, C->Get() ); - - // write centroid for components of assemblies - if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) { - TDF_LabelSequence seq; - XCAFDoc_ShapeTool::GetComponents ( L, seq ); - for (Standard_Integer k=1; k <= seq.Length(); k++) { - TDF_Label lab = seq(k); - - // get shape with correct location - TDF_Label Lref; - if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) || - ! myLabels.IsBound ( Lref ) ) continue; - TopLoc_Location Loc = XCAFDoc_ShapeTool::GetLocation ( lab ); - S = myLabels.Find ( Lref ); - S.Move ( Loc ); - - C.Nullify(); - lab.FindAttribute ( XCAFDoc_Centroid::GetID(), C ); - // if centroid is not assigned to an instance, - // use (shifted) centroid of original shape - gp_Pnt center; - if ( C.IsNull() ) { - Lref.FindAttribute ( XCAFDoc_Centroid::GetID(), C ); - if ( C.IsNull() ) continue; - center = C->Get().Transformed ( Loc.Transformation() ); - } - else center = C->Get(); - - Props.AddCentroid ( S, center, Standard_True ); - } - } -*/ + WritePropsForLabel(theWS, myLabels, aLabel, theIsMulti); } return Standard_True; } - //======================================================================= -//function : WriteLayers -//purpose : +//function : writeLayers +//purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::WriteLayers (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels ) const +Standard_Boolean STEPCAFControl_Writer::writeLayers(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const { - - if ( labels.Length() <=0 ) return Standard_False; + + if (theLabels.IsEmpty()) + return Standard_False; // get working data - const Handle(Interface_InterfaceModel) &Model = WS->Model(); - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); - Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( labels(1) ); - if (LTool.IsNull() ) return Standard_False; - - TDF_LabelSequence LayerLS; - LTool->GetLayerLabels(LayerLS); - if ( LayerLS.Length() <=0 ) return Standard_False; - - // Iterate on requested layers and for each layer take set of shapes. - for ( Standard_Integer i=1; i <= LayerLS.Length(); i++ ) { - TDF_Label L = LayerLS.Value(i); - + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + TDF_LabelSequence aGlobalLayerLS; + // Iterate on requested shapes collect Tools + for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + Handle(XCAFDoc_LayerTool) aLTool = XCAFDoc_DocumentTool::LayerTool(aLabel); + TDF_LabelSequence aLayerLS; + aLTool->GetLayerLabels(aLayerLS); + aGlobalLayerLS.Append(aLayerLS); + } + for (TDF_LabelSequence::Iterator aLayerIter(aGlobalLayerLS); + aLayerIter.More(); aLayerIter.Next()) + { + const TDF_Label& aLayerL = aLayerIter.Value(); // get labels of shapes in that layer - TDF_LabelSequence ShapeLs; - LTool->GetShapesOfLayer(L, ShapeLs); - if ( ShapeLs.Length() <=0 ) continue; - + TDF_LabelSequence aShapeLabels; + XCAFDoc_LayerTool::GetShapesOfLayer(aLayerL, aShapeLabels); + if (aShapeLabels.IsEmpty()) + continue; + // name of layer: if not set, is considered as being empty - Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString; - GetLabelName ( L, hName ); + Handle(TCollection_HAsciiString) aHName = new TCollection_HAsciiString; + GetLabelName(aLayerL, aHName); // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment items. - TColStd_SequenceOfTransient seqRI; - for ( Standard_Integer j=1; j <= ShapeLs.Length(); j++) { - TDF_Label shLabel = ShapeLs.Value(j); - if ( shLabel.IsNull() ) continue; - - // there is no way to assign layer to instance in STEP - if ( XCAFDoc_ShapeTool::IsAssembly ( shLabel ) || - XCAFDoc_ShapeTool::IsReference ( shLabel ) ) + TColStd_SequenceOfTransient aSeqRI; + for (TDF_LabelSequence::Iterator aShapeIter(aShapeLabels); + aShapeIter.More(); aShapeIter.Next()) + { + const TDF_Label& aShLabel = aShapeIter.Value(); + if (aShLabel.IsNull()) continue; - + + // there is no way to assign layer to instance in STEP + if (XCAFDoc_ShapeTool::IsAssembly(aShLabel) || + XCAFDoc_ShapeTool::IsReference(aShLabel)) + { + continue; + } // check that the shape is one of (uub)labels written during current transfer - Standard_Integer k = 1; - for ( ; k <= labels.Length(); k++ ) - if ( shLabel.IsDescendant ( labels(k) ) ) break; - if ( k > labels.Length() ) continue; + Standard_Boolean anIsWritten = Standard_False; + for (TDF_LabelSequence::Iterator aLabelIter(theLabels); + aLabelIter.More(); aLabelIter.Next()) + { + if (aShLabel.IsDescendant(aLabelIter.Value())) + { + anIsWritten = Standard_True; + break; + } + } + if (!anIsWritten) + { + continue; + } // get target STEP entity - TopoDS_Shape oneShape = XCAFDoc_ShapeTool::GetShape(shLabel); - - TopLoc_Location Loc; - Standard_Integer nb = - FindEntities ( FP, oneShape, Loc, seqRI ); - if ( nb <=0 ) - FP->Messenger()->SendInfo() << "Warning: Cannot find RI for " << oneShape.TShape()->DynamicType()->Name() << std::endl; + TopoDS_Shape anOneShape = XCAFDoc_ShapeTool::GetShape(aShLabel); + + TopLoc_Location aLoc; + Standard_Integer aNb = FindEntities(aFP, anOneShape, aLoc, aSeqRI); + if (aNb <= 0) + { + Message::SendTrace() << "Warning: Cannot find RI for " << anOneShape.TShape()->DynamicType()->Name() << "\n"; + } } - if ( seqRI.Length() <= 0 ) continue; + if (aSeqRI.IsEmpty()) + continue; // analyze visibility - Handle(StepVisual_PresentationLayerAssignment) StepLayerAs = new StepVisual_PresentationLayerAssignment; - Handle(TCollection_HAsciiString) descr; + Handle(StepVisual_PresentationLayerAssignment) aStepLayerAs = new StepVisual_PresentationLayerAssignment; + Handle(TCollection_HAsciiString) aDescr; Handle(TDataStd_UAttribute) aUAttr; Standard_Boolean isLinv = Standard_False; - if (L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)) { - descr = new TCollection_HAsciiString ("invisible"); -#ifdef OCCT_DEBUG - std::cout << "\tLayer \"" << hName->String().ToCString() << "\" is invisible"<String().ToCString() << "\" is invisible" << "\n"; isLinv = Standard_True; } - else descr = new TCollection_HAsciiString ("visible"); - - // create layer entity - Handle(StepVisual_HArray1OfLayeredItem) HArrayOfLItem = - new StepVisual_HArray1OfLayeredItem ( 1, seqRI.Length() ); - for (Standard_Integer i1 = 1; i1<=seqRI.Length(); i1++) { - StepVisual_LayeredItem LI; - LI.SetValue ( seqRI.Value(i1) ); - HArrayOfLItem->SetValue( i1, LI ); + else + { + aDescr = new TCollection_HAsciiString("visible"); } - StepLayerAs->Init(hName, descr, HArrayOfLItem); - Model->AddWithRefs( StepLayerAs ); + + // create layer entity + Standard_Integer anSetStyleInd = 1; + Handle(StepVisual_HArray1OfLayeredItem) aHArrayOfLItem = + new StepVisual_HArray1OfLayeredItem(1, aSeqRI.Length()); + for (TColStd_SequenceOfTransient::Iterator aRIIter(aSeqRI); + aRIIter.More(); aRIIter.Next()) + { + StepVisual_LayeredItem aLI; + aLI.SetValue(aRIIter.Value()); + aHArrayOfLItem->SetValue(anSetStyleInd++, aLI); + } + aStepLayerAs->Init(aHName, aDescr, aHArrayOfLItem); + aModel->AddWithRefs(aStepLayerAs); // PTV 23.01.2003 add the invisibility AFTER adding layer into the model. // add the invisibility for the layer - if (isLinv) { + if (isLinv) + { // Invisibility Item for containing invisible layers. - Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = new StepVisual_HArray1OfInvisibleItem (1,1); - StepVisual_InvisibleItem InvIt; - InvIt.SetValue( StepLayerAs ); - HInvsblItm->SetValue( 1, InvIt); - - Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility(); - Invsblt->Init( HInvsblItm ); - Model->AddWithRefs( Invsblt ); + Handle(StepVisual_HArray1OfInvisibleItem) aHInvsblItm = new StepVisual_HArray1OfInvisibleItem(1, 1); + StepVisual_InvisibleItem aInvIt; + aInvIt.SetValue(aStepLayerAs); + aHInvsblItm->SetValue(1, aInvIt); + + Handle(StepVisual_Invisibility) aInvsblt = new StepVisual_Invisibility(); + aInvsblt->Init(aHInvsblItm); + aModel->AddWithRefs(aInvsblt); } } return Standard_True; } - //======================================================================= //function : getSHUOstyle //purpose : auxiliary //======================================================================= -static Standard_Boolean getSHUOstyle(const TDF_Label& aSHUOlab, - const Handle(XCAFDoc_ColorTool)& CTool, - const Handle(XCAFDoc_VisMaterialTool)& theMatTool, - XCAFPrs_Style& SHUOstyle) +static Standard_Boolean getSHUOstyle(const TDF_Label& theSHUOlab, + XCAFPrs_Style& theSHUOstyle) { - Quantity_Color C; - if (!CTool->IsVisible( aSHUOlab ) ) - SHUOstyle.SetVisibility(Standard_False); - else { - if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) { - SHUOstyle.SetColorCurv ( C ); - SHUOstyle.SetColorSurf ( C ); - } - if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) ) - SHUOstyle.SetColorSurf ( C ); - if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) ) - SHUOstyle.SetColorCurv ( C ); - if (!SHUOstyle.IsSetColorSurf()) + Quantity_Color aColor; + if (!XCAFDoc_ColorTool::IsVisible(theSHUOlab)) + { + theSHUOstyle.SetVisibility(Standard_False); + } + else + { + if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorGen, aColor)) { - Handle(XCAFDoc_VisMaterial) aVisMat = theMatTool->GetShapeMaterial (aSHUOlab); + theSHUOstyle.SetColorCurv(aColor); + theSHUOstyle.SetColorSurf(aColor); + } + if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorSurf, aColor)) + theSHUOstyle.SetColorSurf(aColor); + if (XCAFDoc_ColorTool::GetColor(theSHUOlab, XCAFDoc_ColorCurv, aColor)) + theSHUOstyle.SetColorCurv(aColor); + if (!theSHUOstyle.IsSetColorSurf()) + { + Handle(XCAFDoc_VisMaterial) aVisMat = XCAFDoc_VisMaterialTool::GetShapeMaterial(theSHUOlab); if (!aVisMat.IsNull() - && !aVisMat->IsEmpty()) + && !aVisMat->IsEmpty()) { // only color can be stored in STEP - SHUOstyle.SetColorSurf (aVisMat->BaseColor()); + theSHUOstyle.SetColorSurf(aVisMat->BaseColor()); } } } - if ( !SHUOstyle.IsSetColorCurv() && - !SHUOstyle.IsSetColorSurf() && - SHUOstyle.IsVisible() ) + if (!theSHUOstyle.IsSetColorCurv() && + !theSHUOstyle.IsSetColorSurf() && + theSHUOstyle.IsVisible()) + { return Standard_False; + } return Standard_True; } - //======================================================================= //function : getProDefinitionOfNAUO //purpose : auxiliary //======================================================================= -static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& WS, +static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& theWS, const TopoDS_Shape& theShape, - Handle(StepBasic_ProductDefinition)& PD, - Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO, - Standard_Boolean IsRelating) + Handle(StepBasic_ProductDefinition)& thePD, + Handle(StepRepr_NextAssemblyUsageOccurrence)& theNAUO, + Standard_Boolean theIsRelating) { - if ( theShape.IsNull() ) + if (theShape.IsNull()) return Standard_False; // get CDSR - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); - Handle(StepShape_ContextDependentShapeRepresentation) CDSR; - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, theShape ); - if (!FP->FindTypedTransient(mapper, - STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), - CDSR)) + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + Handle(StepShape_ContextDependentShapeRepresentation) aCDSR; + Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, theShape); + if (!aFP->FindTypedTransient(aMapper, + STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), + aCDSR)) + { return Standard_False; + } // get PDS of NAUO - Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation(); - if (PDS.IsNull()) + Handle(StepRepr_ProductDefinitionShape) aPDS = aCDSR->RepresentedProductRelation(); + if (aPDS.IsNull()) return Standard_False; // get the NAUO entity - Interface_Graph aGraph = WS->HGraph()->Graph(); - Interface_EntityIterator subs = aGraph.Shareds(PDS); - for ( subs.Start(); subs.More(); subs.Next() ) { - if (!subs.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) - continue; - NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value()); - break; + Interface_Graph aGraph = theWS->HGraph()->Graph(); + for (Interface_EntityIterator aShareds = aGraph.Shareds(aPDS); aShareds.More(); aShareds.Next()) + { + theNAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(aShareds.Value()); + if (!theNAUO.IsNull()) + { + break; + } } - if ( NAUO.IsNull() ) + if (theNAUO.IsNull()) return Standard_False; // get Relatinf or Related product definition - if ( !IsRelating ) - PD = NAUO->RelatedProductDefinition(); + if (!theIsRelating) + thePD = theNAUO->RelatedProductDefinition(); else - PD = NAUO->RelatingProductDefinition(); - if ( PD.IsNull() ) + thePD = theNAUO->RelatingProductDefinition(); + if (thePD.IsNull()) return Standard_False; return Standard_True; } - //======================================================================= //function : writeSHUO //purpose : auxiliary //======================================================================= -static Standard_Boolean writeSHUO (const Handle(XCAFDoc_GraphNode)& theSHUO, - const Handle(XCAFDoc_ShapeTool)& theSTool, - const Handle(XSControl_WorkSession)& WS, - Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO, - TopoDS_Shape& NAUOShape, - Handle(StepBasic_ProductDefinition)& theRelatingPD, - Standard_Boolean& isDeepest) +static Standard_Boolean writeSHUO(const Handle(XCAFDoc_GraphNode)& theSHUO, + const Handle(XSControl_WorkSession)& theWS, + Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO, + TopoDS_Shape& theNAUOShape, + Handle(StepBasic_ProductDefinition)& theRelatingPD, + Standard_Boolean& theIsDeepest) { // set the ProductDefinitionRelationship descriptin information as empty strings. - Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString(""); - + Handle(TCollection_HAsciiString) anEmptyString = new TCollection_HAsciiString(""); + TDF_LabelSequence aNextUsageLabs; - theSTool->GetSHUONextUsage( theSHUO->Label(), aNextUsageLabs ); - Handle(XCAFDoc_GraphNode) NuSHUO; - if ( theTopSHUO.IsNull() ) { + XCAFDoc_ShapeTool::GetSHUONextUsage(theSHUO->Label(), aNextUsageLabs); + Handle(XCAFDoc_GraphNode) aNuSHUO; + if (theTopSHUO.IsNull()) + { // the top SHUO if (aNextUsageLabs.Length() < 1) return Standard_False; - theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO ); - if (NuSHUO.IsNull()) + XCAFDoc_ShapeTool::GetSHUO(aNextUsageLabs.Value(1), aNuSHUO); + if (aNuSHUO.IsNull()) return Standard_False; // get relating product definition - TopoDS_Shape aTopCompShape = theSTool->GetShape( theSHUO->Label().Father() ); - Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO; - if (!getProDefinitionOfNAUO( WS, aTopCompShape, - theRelatingPD, UUNAUO, Standard_True )) + TopoDS_Shape aTopCompShape = XCAFDoc_ShapeTool::GetShape(theSHUO->Label().Father()); + Handle(StepRepr_NextAssemblyUsageOccurrence) aRelatingNAUO; + if (!getProDefinitionOfNAUO(theWS, aTopCompShape, + theRelatingPD, aRelatingNAUO, Standard_True)) + { return Standard_False; + } // get related product definition - TopoDS_Shape aNUShape = theSTool->GetShape( NuSHUO->Label().Father() ); + TopoDS_Shape aNUShape = XCAFDoc_ShapeTool::GetShape(aNuSHUO->Label().Father()); Handle(StepBasic_ProductDefinition) aRelatedPD; - Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO; - if (!getProDefinitionOfNAUO( WS, aNUShape, - aRelatedPD, NUNAUO, Standard_False )) + Handle(StepRepr_NextAssemblyUsageOccurrence) aRelatedNAUO; + if (!getProDefinitionOfNAUO(theWS, aNUShape, + aRelatedPD, aRelatedNAUO, Standard_False)) + { return Standard_False; - + } + theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence; // create deepest shuo EmptyString - theTopSHUO->Init(/*id*/EmptyString, /*name*/EmptyString, - /*no description*/Standard_False,/*description*/EmptyString, + theTopSHUO->Init(/*id*/anEmptyString, /*name*/anEmptyString, + /*no description*/Standard_False,/*description*/anEmptyString, theRelatingPD, aRelatedPD, - /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString, - /*upper_usage*/UUNAUO, /*next_usage*/NUNAUO); + /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/anEmptyString, + /*upper_usage*/aRelatingNAUO, /*next_usage*/aRelatedNAUO); // write the other SHUO. - if(!writeSHUO( NuSHUO, theSTool, WS, theTopSHUO, NAUOShape, theRelatingPD, isDeepest )) { + if (!writeSHUO(aNuSHUO, theWS, theTopSHUO, theNAUOShape, theRelatingPD, theIsDeepest)) + { theTopSHUO.Nullify(); return Standard_False; } - + return Standard_True; } -// Handle(XCAFDoc_GraphNode) NuSHUO; - if ( aNextUsageLabs.Length() > 0) { + // Handle(XCAFDoc_GraphNode) NuSHUO; + if (aNextUsageLabs.Length() > 0) + { // store SHUO recursive -#ifdef OCCT_DEBUG - if ( aNextUsageLabs.Length() > 1 ) - std::cout << "Warning: store only one next_usage of current SHUO" << std::endl; -#endif - theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO ); + if (aNextUsageLabs.Length() > 1) + Message::SendTrace() << "Warning: store only one next_usage of current SHUO" << "\n"; + XCAFDoc_ShapeTool::GetSHUO(aNextUsageLabs.Value(1), aNuSHUO); Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO = new StepRepr_SpecifiedHigherUsageOccurrence; - if (!writeSHUO( NuSHUO, theSTool, WS, aNUEntSHUO, NAUOShape, theRelatingPD, isDeepest )) + if (!writeSHUO(aNuSHUO, theWS, aNUEntSHUO, theNAUOShape, theRelatingPD, theIsDeepest)) return Standard_False; - + // store the deepest SHUO to the dociment TopoDS_Shape aNUSh, aUUSh; - aNUSh = theSTool->GetShape( NuSHUO->Label().Father() ); - aUUSh = theSTool->GetShape( theSHUO->Label().Father() ); + aNUSh = XCAFDoc_ShapeTool::GetShape(aNuSHUO->Label().Father()); + aUUSh = XCAFDoc_ShapeTool::GetShape(theSHUO->Label().Father()); // get relating PD with upper_usage and related PD with next_usage Handle(StepBasic_ProductDefinition) nullPD;// no need to use,case have shared Handle(StepBasic_ProductDefinition) aRelatedPD; Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO; - if (!getProDefinitionOfNAUO( WS, aUUSh, nullPD, UUNAUO, Standard_True ) || - !getProDefinitionOfNAUO( WS, aNUSh, aRelatedPD, NUNAUO, Standard_False )) { -#ifdef OCCT_DEBUG - std::cout << "Warning: cannot get related or relating PD" << std::endl; -#endif + if (!getProDefinitionOfNAUO(theWS, aUUSh, nullPD, UUNAUO, Standard_True) || + !getProDefinitionOfNAUO(theWS, aNUSh, aRelatedPD, NUNAUO, Standard_False)) + { + Message::SendTrace() << "Warning: cannot get related or relating PD" << "\n"; return Standard_False; } - aNUEntSHUO->Init(/*id*/EmptyString, /*name*/EmptyString, - /*no description*/Standard_False,/*description*/EmptyString, + aNUEntSHUO->Init(/*id*/anEmptyString, /*name*/anEmptyString, + /*no description*/Standard_False,/*description*/anEmptyString, theRelatingPD, aRelatedPD, - /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString, + /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/anEmptyString, /*upper_usage*/theTopSHUO, /*next_usage*/NUNAUO); - if ( isDeepest ) { - isDeepest = Standard_False; + if (theIsDeepest) + { + theIsDeepest = Standard_False; } - WS->Model()->AddWithRefs ( aNUEntSHUO ); + theWS->Model()->AddWithRefs(aNUEntSHUO); return Standard_True; } // end of recurse storing - - // get shape + + // get shape TDF_Label aShapeL = theSHUO->Label().Father(); - NAUOShape = theSTool->GetShape( aShapeL ); + theNAUOShape = XCAFDoc_ShapeTool::GetShape(aShapeL); // return to the deepest level from SHUO shape level // it is because SHUO is attribute on deep level and shape level. - isDeepest = Standard_True; + theIsDeepest = Standard_True; return Standard_True; } - //======================================================================= //function : createSHUOStyledItem //purpose : auxiliary //======================================================================= -static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style, - const Handle(StepRepr_ProductDefinitionShape)& PDS, - const Handle(XSControl_WorkSession) &WS, - const TopoDS_Shape& Sh, - const Handle(XCAFDoc_ShapeTool)& STool, - MoniTool_DataMapOfShapeTransient& myMapCompMDGPR) +static Standard_Boolean createSHUOStyledItem(const XCAFPrs_Style& theStyle, + const Handle(StepRepr_ProductDefinitionShape)& thePDS, + const Handle(XSControl_WorkSession)& theWS, + const TopoDS_Shape& theShape, + const Handle(XCAFDoc_ShapeTool)& theSTool, + MoniTool_DataMapOfShapeTransient& theMapCompMDGPR) { // create styled item for the indicated SHUO and store to the model - STEPConstruct_Styles Styles( WS ); + STEPConstruct_Styles aStyles(theWS); // translate colors to STEP - Handle(StepVisual_Colour) surfColor, curvColor; - Standard_Real RenderTransp = 0.0; - if ( style.IsSetColorSurf() ) { - Quantity_ColorRGBA sCol = style.GetColorSurfRGBA(); - RenderTransp = 1.0 - sCol.Alpha(); - surfColor = Styles.EncodeColor ( sCol.GetRGB() ); + Handle(StepVisual_Colour) aSurfColor, aCurvColor; + Standard_Real aRenderTransp = 0.0; + if (theStyle.IsSetColorSurf()) + { + Quantity_ColorRGBA aSurfCol = theStyle.GetColorSurfRGBA(); + aRenderTransp = 1.0 - aSurfCol.Alpha(); + aSurfColor = aStyles.EncodeColor(aSurfCol.GetRGB()); } - if ( style.IsSetColorCurv() ) - curvColor = Styles.EncodeColor ( style.GetColorCurv() ); + if (theStyle.IsSetColorCurv()) + aCurvColor = aStyles.EncodeColor(theStyle.GetColorCurv()); Standard_Boolean isComponent = Standard_True;// cause need to get PSBC - Handle(StepRepr_RepresentationItem) item; + Handle(StepRepr_RepresentationItem) anItem; // set default color for invisible SHUO. Standard_Boolean isSetDefaultColor = Standard_False; - if (surfColor.IsNull() && curvColor.IsNull() && !style.IsVisible() ) { - surfColor = Styles.EncodeColor ( Quantity_Color(Quantity_NOC_WHITE) ); + if (aSurfColor.IsNull() && aCurvColor.IsNull() && !theStyle.IsVisible()) + { + aSurfColor = aStyles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE)); isSetDefaultColor = Standard_True; } - Handle(StepVisual_PresentationStyleAssignment) PSA = - Styles.MakeColorPSA ( item, surfColor, curvColor, surfColor, RenderTransp, isComponent ); - Handle(StepVisual_StyledItem) override; //null styled item - + Handle(StepVisual_PresentationStyleAssignment) aPSA = + aStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aSurfColor, aRenderTransp, isComponent); + Handle(StepVisual_StyledItem) anOverride; //null styled item + // find the repr item of the shape - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); - Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh ); - Handle(StepShape_ContextDependentShapeRepresentation) CDSR; - FP->FindTypedTransient(mapper, - STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), - CDSR); - if ( CDSR.IsNull() ) + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + Handle(TransferBRep_ShapeMapper) aMapper = TransferBRep::ShapeMapper(aFP, theShape); + Handle(StepShape_ContextDependentShapeRepresentation) aCDSR; + aFP->FindTypedTransient(aMapper, + STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), + aCDSR); + if (aCDSR.IsNull()) return Standard_False; // find context - Handle(StepRepr_RepresentationContext) Context = Styles.FindContext( Sh ); - TopoDS_Shape aTopSh = Sh; - if (Context.IsNull()) { - TDF_Label aTopShL = STool->FindShape(Sh, Standard_False); + Handle(StepRepr_RepresentationContext) aContext = aStyles.FindContext(theShape); + TopoDS_Shape aTopSh = theShape; + if (aContext.IsNull()) + { + TDF_Label aTopShL = theSTool->FindShape(theShape, Standard_False); if (aTopShL.IsNull()) return Standard_False; - aTopSh = STool->GetShape( aTopShL ); - Context = Styles.FindContext ( aTopSh ); + aTopSh = XCAFDoc_ShapeTool::GetShape(aTopShL); + aContext = aStyles.FindContext(aTopSh); } - if (Context.IsNull()) + if (aContext.IsNull()) return Standard_False; // get representation item of the shape - TopLoc_Location L; - TColStd_SequenceOfTransient seqRI; - FindEntities ( FP, Sh, L, seqRI ); -#ifdef OCCT_DEBUG - if ( seqRI.Length() <=0 ) - std::cout << "Warning: Cannot find RI for " << Sh.TShape()->DynamicType()->Name() << std::endl; -#endif - item = Handle(StepRepr_RepresentationItem)::DownCast(seqRI(1)); + TopLoc_Location aLocation; + TColStd_SequenceOfTransient aSeqRI; + FindEntities(aFP, theShape, aLocation, aSeqRI); + if (aSeqRI.Length() <= 0) + Message::SendTrace() << "Warning: Cannot find RI for " << theShape.TShape()->DynamicType()->Name() << "\n"; + anItem = Handle(StepRepr_RepresentationItem)::DownCast(aSeqRI(1)); //get overridden styled item - getStyledItem(Sh,STool, Styles, override,myMapCompMDGPR); - + getStyledItem(theShape, theSTool, aStyles, anOverride, theMapCompMDGPR); + // get STEP STYLED ITEM - Handle(StepVisual_StyledItem) STEPstyle = Styles.AddStyle ( item, PSA, override ); + Handle(StepVisual_StyledItem) aSTEPstyle = aStyles.AddStyle(anItem, aPSA, anOverride); // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC - Styles.CreateNAUOSRD( Context, CDSR, PDS ); - + aStyles.CreateNAUOSRD(aContext, aCDSR, thePDS); + // add step styled item of SHUO to the model // do it by additing styled item to the MDGPR - if ( !aTopSh.IsNull() && !myMapCompMDGPR.IsBound( aTopSh ) ) { + if (!aTopSh.IsNull() && !theMapCompMDGPR.IsBound(aTopSh)) + { // create MDGPR and record it in model -#ifdef OCCT_DEBUG - std::cout << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << std::endl; -#endif + Message::SendTrace() << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << "\n"; Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR; - Styles.CreateMDGPR ( Context, aMDGPR ); + aStyles.CreateMDGPR(aContext, aMDGPR); if (!aMDGPR.IsNull()) - myMapCompMDGPR.Bind( aTopSh, aMDGPR ); + theMapCompMDGPR.Bind(aTopSh, aMDGPR); } - else if ( !aTopSh.IsNull() && myMapCompMDGPR.IsBound( aTopSh ) ) { + else if (!aTopSh.IsNull() && theMapCompMDGPR.IsBound(aTopSh)) + { // get MDGPR of the top-level shape - Handle(StepVisual_PresentationRepresentation) aMDGPR = - Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) ); + Handle(StepVisual_PresentationRepresentation) aMDGPR = + Handle(StepVisual_PresentationRepresentation)::DownCast(theMapCompMDGPR.Find(aTopSh)); // get old styled items to not lose it - Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items(); - Standard_Integer oldLengthlen = 0; - if (!oldItems.IsNull()) - oldLengthlen = oldItems->Length(); + Handle(StepRepr_HArray1OfRepresentationItem) anOldItems = aMDGPR->Items(); + Standard_Integer anOldLengthlen = 0; + if (!anOldItems.IsNull()) + anOldLengthlen = anOldItems->Length(); // create new array of styled items by an olds and new one - Handle(StepRepr_HArray1OfRepresentationItem) newItems = - new StepRepr_HArray1OfRepresentationItem(1, oldLengthlen + 1); - Standard_Integer si; - Standard_Integer el = 1; - for ( si=1; si <= oldLengthlen; si++ ) - newItems->SetValue( el++, oldItems->Value( si ) ); - newItems->SetValue (el++, STEPstyle); + Handle(StepRepr_HArray1OfRepresentationItem) aNewItems = + new StepRepr_HArray1OfRepresentationItem(1, anOldLengthlen + 1); + Standard_Integer aSetStyleInd = 1; + for (StepRepr_HArray1OfRepresentationItem::Iterator aStyleIter(anOldItems->Array1()); + aStyleIter.More(); aStyleIter.Next()) + { + aNewItems->SetValue(aSetStyleInd++, aStyleIter.Value()); + } + aNewItems->SetValue(aSetStyleInd++, aSTEPstyle); // init MDGPR be new array of styled items - if (newItems->Length() > 0) - aMDGPR->SetItems( newItems ); + if (aNewItems->Length() > 0) + aMDGPR->SetItems(aNewItems); } - else { - WS->Model()->AddWithRefs ( STEPstyle ); // add as root to the model, but it is not good -#ifdef OCCT_DEBUG - std::cout << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, cause cannot find MDGPR" << std::endl; -#endif + else + { + theWS->Model()->AddWithRefs(aSTEPstyle); // add as root to the model, but it is not good + Message::SendTrace() << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, cause cannot find MDGPR" << "\n"; } // create invisibility item for the styled item - if ( !style.IsVisible() ) { - if (isSetDefaultColor) { + if (!theStyle.IsVisible()) + { + if (isSetDefaultColor) + { // try to set default color from top-level shape - - setDefaultInstanceColor(override, PSA); + + setDefaultInstanceColor(anOverride, aPSA); } // create invisibility item and refer for styledItem - Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility(); - Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = - new StepVisual_HArray1OfInvisibleItem (1,1); + Handle(StepVisual_Invisibility) aInvsblt = new StepVisual_Invisibility(); + Handle(StepVisual_HArray1OfInvisibleItem) aHInvsblItm = + new StepVisual_HArray1OfInvisibleItem(1, 1); // put all style item into the harray StepVisual_InvisibleItem anInvItem; - anInvItem.SetValue( STEPstyle ); - HInvsblItm->SetValue( 1, anInvItem ); - Invsblt->Init( HInvsblItm ); - WS->Model()->AddWithRefs( Invsblt ); + anInvItem.SetValue(aSTEPstyle); + aHInvsblItm->SetValue(1, anInvItem); + aInvsblt->Init(aHInvsblItm); + theWS->Model()->AddWithRefs(aInvsblt); } - + return Standard_True; } - //======================================================================= -//function : WriteSHUOs -//purpose : +//function : writeSHUOs +//purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels ) +Standard_Boolean STEPCAFControl_Writer::writeSHUOs(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) { - if ( labels.Length() <=0 ) return Standard_False; - - // get working data - Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) ); - Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool( labels(1) ); - if (CTool.IsNull() ) + if (theLabels.IsEmpty()) return Standard_False; + // map of transferred SHUO TColStd_MapOfTransient aMapOfMainSHUO; // Iterate on requested shapes - for ( Standard_Integer i=1; i <= labels.Length(); i++ ) { - TDF_Label L = labels.Value(i); - if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip - if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) { - TDF_LabelSequence seq; - XCAFDoc_ShapeTool::GetComponents ( L, seq ); - // iterates on components of assembly - for (Standard_Integer k=1; k <= seq.Length(); k++) { - TDF_Label lab = seq(k); - TDF_AttributeSequence anAttrSeq; - CTool->ShapeTool()->GetAllComponentSHUO( lab, anAttrSeq ); - // work with SHUO - for (Standard_Integer j = 1; j <= anAttrSeq.Length(); j++) { - Handle(XCAFDoc_GraphNode) aSHUO = - Handle(XCAFDoc_GraphNode)::DownCast(anAttrSeq.Value( j )); - // take label of SHUO - TDF_Label aSHUOlab = aSHUO->Label(); - TDF_LabelSequence aUpLabels; - // check is it SHUO of upper_usage - CTool->ShapeTool()->GetSHUOUpperUsage( aSHUOlab, aUpLabels ); - if ( aUpLabels.Length() > 0 ) - continue; // transfer only main SHUO - if ( aMapOfMainSHUO.Contains( aSHUO ) ) - continue; // do not try to transfer SHUO twice - aMapOfMainSHUO.Add( aSHUO ); - // check if it is styled SHUO - XCAFPrs_Style SHUOstyle; - if ( !getSHUOstyle ( aSHUOlab, CTool, aMatTool, SHUOstyle ) ) { -#ifdef OCCT_DEBUG - std::cout << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << std::endl; -#endif - continue; - } - // write SHUO to the model amd then add structure type. - TopoDS_Shape NAUOShape; // shape of the deepest NAUO in the SHUO structure - Standard_Boolean isDeepest = Standard_False; - Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO; - Handle(StepBasic_ProductDefinition) aRelatingPD; - // create the top SHUO and all other. - writeSHUO( aSHUO, CTool->ShapeTool(), WS, anEntOfSHUO, NAUOShape, aRelatingPD, isDeepest ); - if ( anEntOfSHUO.IsNull() || NAUOShape.IsNull() ) { -#ifdef OCCT_DEBUG - std::cout << "Warning: " << __FILE__ << ": Cannot store SHUO" << std::endl; -#endif - continue; - } - // create new Product Definition Shape for TOP SHUO -#ifdef OCCT_DEBUG - std::cout << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << std::endl; -#endif - Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape; - Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO"); - Handle(TCollection_HAsciiString) descrStr = new TCollection_HAsciiString(""); - StepRepr_CharacterizedDefinition aCharDef; - aCharDef.SetValue( anEntOfSHUO ); - PDS->Init( aPDSname, Standard_False, descrStr, aCharDef ); - - // create styled item for SHUO and add to the model - createSHUOStyledItem ( SHUOstyle, PDS, WS, NAUOShape, CTool->ShapeTool(), myMapCompMDGPR ); - - } // end work with SHUO - } // end of an assembly components - } // end of IsAssembly case - // nothing to do if it is not assembly - continue; + for (TDF_LabelSequence::Iterator aLabelIter(theLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + if (!myLabels.IsBound(aLabel)) + continue; // not recorded as translated, skip + if (!XCAFDoc_ShapeTool::IsAssembly(aLabel)) + { + continue; + } + TDF_LabelSequence aLabelSeq; + XCAFDoc_ShapeTool::GetComponents(aLabel, aLabelSeq); + // iterates on components of assembly + for (TDF_LabelSequence::Iterator aCompIter(aLabelSeq); + aCompIter.More(); aCompIter.Next()) + { + const TDF_Label& aCompL = aCompIter.Value(); + TDF_AttributeSequence anAttrSeq; + XCAFDoc_ShapeTool::GetAllComponentSHUO(aCompL, anAttrSeq); + // work with SHUO + for (TDF_AttributeSequence::Iterator anAttrIter(anAttrSeq); + anAttrIter.More(); anAttrIter.Next()) + { + Handle(XCAFDoc_GraphNode) aSHUO = + Handle(XCAFDoc_GraphNode)::DownCast(anAttrIter.Value()); + // take label of SHUO + TDF_Label aSHUOlab = aSHUO->Label(); + TDF_LabelSequence aUpLabels; + // check is it SHUO of upper_usage + XCAFDoc_ShapeTool::GetSHUOUpperUsage(aSHUOlab, aUpLabels); + if (aUpLabels.Length() > 0) + continue; // transfer only main SHUO + if (aMapOfMainSHUO.Contains(aSHUO)) + continue; // do not try to transfer SHUO twice + aMapOfMainSHUO.Add(aSHUO); + // check if it is styled SHUO + XCAFPrs_Style aSHUOstyle; + if (!getSHUOstyle(aSHUOlab, aSHUOstyle)) + { + Message::SendTrace() << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << "\n"; + continue; + } + // write SHUO to the model amd then add structure type. + TopoDS_Shape aNAUOShape; // shape of the deepest NAUO in the SHUO structure + Standard_Boolean isDeepest = Standard_False; + Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO; + Handle(StepBasic_ProductDefinition) aRelatingPD; + // create the top SHUO and all other. + writeSHUO(aSHUO, theWS, anEntOfSHUO, aNAUOShape, aRelatingPD, isDeepest); + if (anEntOfSHUO.IsNull() || aNAUOShape.IsNull()) + { + Message::SendTrace() << "Warning: " << __FILE__ << ": Cannot store SHUO" << "\n"; + continue; + } + // create new Product Definition Shape for TOP SHUO + Message::SendTrace() << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << "\n"; + Handle(StepRepr_ProductDefinitionShape) aPDS = new StepRepr_ProductDefinitionShape; + Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO"); + Handle(TCollection_HAsciiString) aDescrStr = new TCollection_HAsciiString(""); + StepRepr_CharacterizedDefinition aCharDef; + aCharDef.SetValue(anEntOfSHUO); + aPDS->Init(aPDSname, Standard_False, aDescrStr, aCharDef); + + // create styled item for SHUO and add to the model + createSHUOStyledItem(aSHUOstyle, aPDS, theWS, aNAUOShape, XCAFDoc_DocumentTool::ShapeTool(aLabel), myMapCompMDGPR); + + } // end work with SHUO + } // end of an assembly components } // end of iterates on indicated labels return Standard_True; } - //======================================================================= //function : FindPDSforDGT //purpose : auxiliary: find PDS for AdvancedFace or EdgeCurve for creation // needed ShapeAspect in D> structure //======================================================================= -static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph, - const Handle(Standard_Transient) &ent, - Handle(StepRepr_ProductDefinitionShape) &PDS, - Handle(StepRepr_RepresentationContext) &RC, - Handle(StepShape_AdvancedFace) &AF, - Handle(StepShape_EdgeCurve) &EC) +static Standard_Boolean FindPDSforDGT(const Interface_Graph& theGraph, + const Handle(Standard_Transient)& theEnt, + Handle(StepRepr_ProductDefinitionShape)& thePDS, + Handle(StepRepr_RepresentationContext)& theRC, + Handle(StepShape_AdvancedFace)& theAF, + Handle(StepShape_EdgeCurve)& theEC) { - if (ent.IsNull()) + if (theEnt.IsNull()) return Standard_False; - if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) && - !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) ) + if (!theEnt->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) && + !theEnt->IsKind(STANDARD_TYPE(StepShape_AdvancedFace))) + { return Standard_False; + } - AF = Handle(StepShape_AdvancedFace)::DownCast(ent); - if( AF.IsNull() ) { - EC = Handle(StepShape_EdgeCurve)::DownCast(ent); - Interface_EntityIterator subs = aGraph.Sharings(EC); - for(subs.Start(); subs.More() && AF.IsNull(); subs.Next()) { - Handle(StepShape_OrientedEdge) OE = Handle(StepShape_OrientedEdge)::DownCast(subs.Value()); - if(OE.IsNull()) continue; - Interface_EntityIterator subs1 = aGraph.Sharings(OE); - for(subs1.Start(); subs1.More() && AF.IsNull(); subs1.Next()) { - Handle(StepShape_EdgeLoop) EL = Handle(StepShape_EdgeLoop)::DownCast(subs1.Value()); - if(EL.IsNull()) continue; - Interface_EntityIterator subs2 = aGraph.Sharings(EL); - for(subs2.Start(); subs2.More() && AF.IsNull(); subs2.Next()) { - Handle(StepShape_FaceBound) FB = Handle(StepShape_FaceBound)::DownCast(subs2.Value()); - if(FB.IsNull()) continue; - Interface_EntityIterator subs3 = aGraph.Sharings(FB); - for(subs3.Start(); subs3.More() && AF.IsNull(); subs3.Next()) { - AF = Handle(StepShape_AdvancedFace)::DownCast(subs3.Value()); + theAF = Handle(StepShape_AdvancedFace)::DownCast(theEnt); + if (theAF.IsNull()) + { + theEC = Handle(StepShape_EdgeCurve)::DownCast(theEnt); + for (Interface_EntityIterator aSharingsIter = theGraph.Sharings(theEC); + aSharingsIter.More() && theAF.IsNull(); aSharingsIter.Next()) + { + Handle(StepShape_OrientedEdge) anOE = Handle(StepShape_OrientedEdge)::DownCast(aSharingsIter.Value()); + if (anOE.IsNull()) + continue; + for (Interface_EntityIterator aSubs1 = theGraph.Sharings(anOE); + aSubs1.More() && theAF.IsNull(); aSubs1.Next()) + { + Handle(StepShape_EdgeLoop) aEL = Handle(StepShape_EdgeLoop)::DownCast(aSubs1.Value()); + if (aEL.IsNull()) + continue; + for (Interface_EntityIterator aSubs2 = theGraph.Sharings(aEL); + aSubs2.More() && theAF.IsNull(); aSubs2.Next()) + { + Handle(StepShape_FaceBound) aFB = Handle(StepShape_FaceBound)::DownCast(aSubs2.Value()); + if (aFB.IsNull()) + continue; + for (Interface_EntityIterator aSubs3 = theGraph.Sharings(aFB); + aSubs3.More() && theAF.IsNull(); aSubs3.Next()) + { + theAF = Handle(StepShape_AdvancedFace)::DownCast(aSubs3.Value()); } } } } } - if(AF.IsNull()) return Standard_False; + if (theAF.IsNull()) + return Standard_False; - Interface_EntityIterator subs = aGraph.Sharings(AF); - for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) { - Handle(StepShape_ConnectedFaceSet) CFS = - Handle(StepShape_ConnectedFaceSet)::DownCast(subs.Value()); - if(CFS.IsNull()) continue; - Interface_EntityIterator subs1 = aGraph.Sharings(CFS); - for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) { - Handle(StepRepr_RepresentationItem) RI = - Handle(StepRepr_RepresentationItem)::DownCast(subs1.Value()); - if(RI.IsNull()) continue; - Interface_EntityIterator subs2 = aGraph.Sharings(RI); - for(subs2.Start(); subs2.More() && PDS.IsNull(); subs2.Next()) { - Handle(StepShape_ShapeRepresentation) SR = - Handle(StepShape_ShapeRepresentation)::DownCast(subs2.Value()); - if(SR.IsNull()) continue; - RC = SR->ContextOfItems(); - Interface_EntityIterator subs3 = aGraph.Sharings(SR); - for(subs3.Start(); subs3.More() && PDS.IsNull(); subs3.Next()) { - Handle(StepShape_ShapeDefinitionRepresentation) SDR = - Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value()); - if(SDR.IsNull()) continue; - Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition(); - if(PropD.IsNull()) continue; - PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD); + for (Interface_EntityIterator aSharingsIter = theGraph.Sharings(theAF); + aSharingsIter.More() && thePDS.IsNull(); aSharingsIter.Next()) + { + Handle(StepShape_ConnectedFaceSet) aCFS = + Handle(StepShape_ConnectedFaceSet)::DownCast(aSharingsIter.Value()); + if (aCFS.IsNull()) + continue; + for (Interface_EntityIterator aSubs1 = theGraph.Sharings(aCFS); + aSubs1.More() && thePDS.IsNull(); aSubs1.Next()) + { + Handle(StepRepr_RepresentationItem) aRI = + Handle(StepRepr_RepresentationItem)::DownCast(aSubs1.Value()); + if (aRI.IsNull()) + continue; + for (Interface_EntityIterator aSubs2 = theGraph.Sharings(aRI); + aSubs2.More() && thePDS.IsNull(); aSubs2.Next()) + { + Handle(StepShape_ShapeRepresentation) aSR = + Handle(StepShape_ShapeRepresentation)::DownCast(aSubs2.Value()); + if (aSR.IsNull()) + continue; + theRC = aSR->ContextOfItems(); + for (Interface_EntityIterator aSubs3 = theGraph.Sharings(aSR); + aSubs3.More() && thePDS.IsNull(); aSubs3.Next()) + { + Handle(StepShape_ShapeDefinitionRepresentation) aSDR = + Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSubs3.Value()); + if (aSDR.IsNull()) + continue; + Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition(); + if (aPropD.IsNull()) + continue; + thePDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD); } } } } - return Standard_True; } @@ -2199,23 +2172,25 @@ static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph, //function : FindPDS //purpose : auxiliary: find Product_definition_shape entity for given entity //======================================================================= -static Handle(StepRepr_ProductDefinitionShape) FindPDS(const Interface_Graph &theGraph, - const Handle(Standard_Transient) &theEnt, - Handle(StepRepr_RepresentationContext) &theRC) +static Handle(StepRepr_ProductDefinitionShape) FindPDS(const Interface_Graph& theGraph, + const Handle(Standard_Transient)& theEnt, + Handle(StepRepr_RepresentationContext)& theRC) { if (theEnt.IsNull()) return NULL; Handle(StepRepr_ProductDefinitionShape) aPDS; // try to find shape_representation in sharings - Interface_EntityIterator anIter = theGraph.Sharings(theEnt); - for (anIter.Start(); anIter.More() && aPDS.IsNull(); anIter.Next()) { + for (Interface_EntityIterator anIter = theGraph.Sharings(theEnt); + anIter.More() && aPDS.IsNull(); anIter.Next()) + { Handle(StepShape_ShapeRepresentation) aSR = Handle(StepShape_ShapeRepresentation)::DownCast(anIter.Value()); if (aSR.IsNull()) continue; theRC = aSR->ContextOfItems(); Interface_EntityIterator aSDRIt = theGraph.Sharings(aSR); - for (aSDRIt.Start(); aSDRIt.More() && aPDS.IsNull(); aSDRIt.Next()) { + for (aSDRIt.Start(); aSDRIt.More() && aPDS.IsNull(); aSDRIt.Next()) + { Handle(StepShape_ShapeDefinitionRepresentation) aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value()); if (aSDR.IsNull()) continue; @@ -2227,17 +2202,17 @@ static Handle(StepRepr_ProductDefinitionShape) FindPDS(const Interface_Graph &th if (!aPDS.IsNull()) return aPDS; - anIter = theGraph.Sharings(theEnt); - for (anIter.Start(); anIter.More(); anIter.Next()) { + for (Interface_EntityIterator anIter = theGraph.Sharings(theEnt); + anIter.More(); anIter.Next()) + { if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)) || - anIter.Value()->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem))) + anIter.Value()->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem))) { aPDS = FindPDS(theGraph, anIter.Value(), theRC); if (!aPDS.IsNull()) return aPDS; } } - return aPDS; } @@ -2246,30 +2221,42 @@ static Handle(StepRepr_ProductDefinitionShape) FindPDS(const Interface_Graph &th //purpose : auxiliary //======================================================================= static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theRC, - const Standard_Boolean isAngle = Standard_False) + const Standard_Boolean theIsAngle = Standard_False) { StepBasic_Unit aUnit; Handle(StepBasic_NamedUnit) aCurrentUnit; - if (isAngle) { + if (theIsAngle) + { Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx = Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC); - if(!aCtx.IsNull()) { - for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) { - if (aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit)) || - aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))) { - aCurrentUnit = aCtx->UnitsValue(j); + if (!aCtx.IsNull()) + { + for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx->Units()->Array1()); + aUnitIter.More(); aUnitIter.Next()) + { + const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value(); + if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit)) || + aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))) + { + aCurrentUnit = aCurUnitValue; break; } } } - if (aCurrentUnit.IsNull()) { + if (aCurrentUnit.IsNull()) + { Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 = Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC); - if(!aCtx1.IsNull()) { - for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) { - if (aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit)) || - aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))) { - aCurrentUnit = aCtx1->UnitsValue(j); + if (!aCtx1.IsNull()) + { + for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx1->Units()->Array1()); + aUnitIter.More(); aUnitIter.Next()) + { + const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value(); + if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit)) || + aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))) + { + aCurrentUnit = aCurUnitValue; break; } } @@ -2278,26 +2265,38 @@ static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theR if (aCurrentUnit.IsNull()) aCurrentUnit = new StepBasic_SiUnitAndPlaneAngleUnit; } - else { + else + { Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) aCtx = Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(theRC); - if(!aCtx.IsNull()) { - for(Standard_Integer j = 1; j <= aCtx->NbUnits(); j++) { - if (aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)) || - aCtx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) { - aCurrentUnit = aCtx->UnitsValue(j); + if (!aCtx.IsNull()) + { + for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx->Units()->Array1()); + aUnitIter.More(); aUnitIter.Next()) + { + const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value(); + if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)) || + aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) + { + aCurrentUnit = aCurUnitValue; break; } } } - if (aCurrentUnit.IsNull()) { + if (aCurrentUnit.IsNull()) + { Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) aCtx1 = Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(theRC); - if(!aCtx1.IsNull()) { - for(Standard_Integer j = 1; j <= aCtx1->NbUnits(); j++) { - if (aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)) || - aCtx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) { - aCurrentUnit = aCtx1->UnitsValue(j); + if (!aCtx1.IsNull()) + { + for (StepBasic_HArray1OfNamedUnit::Iterator aUnitIter(aCtx1->Units()->Array1()); + aUnitIter.More(); aUnitIter.Next()) + { + const Handle(StepBasic_NamedUnit)& aCurUnitValue = aUnitIter.Value(); + if (aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)) || + aCurUnitValue->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))) + { + aCurrentUnit = aCurUnitValue; break; } } @@ -2319,8 +2318,8 @@ static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(const Standard const StepBasic_Unit theUnit, const Handle(TCollection_HAsciiString)& theName, const Standard_CString theMeasureName, - const Standard_Boolean isAngle, - const Standard_Boolean isQualified = Standard_False, + const Standard_Boolean theIsAngle, + const Standard_Boolean theIsQualified = Standard_False, const Handle(StepShape_QualifiedRepresentationItem)& theQRI = NULL) { Handle(StepRepr_RepresentationItem) aReprItem = new StepRepr_RepresentationItem(); @@ -2330,33 +2329,39 @@ static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(const Standard aValueMember->SetName(theMeasureName); aValueMember->SetReal(theValue); aMWU->Init(aValueMember, theUnit); - if (isQualified) { - if (isAngle) { + if (theIsQualified) + { + if (theIsAngle) + { // Angle & with qualifiers - Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI) anItem = + Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI) anItem = new StepRepr_ReprItemAndPlaneAngleMeasureWithUnitAndQRI(); anItem->Init(aMWU, aReprItem, theQRI); return anItem; } - else { + else + { // Length & with qualifiers - Handle(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI) anItem = + Handle(StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI) anItem = new StepRepr_ReprItemAndLengthMeasureWithUnitAndQRI(); anItem->Init(aMWU, aReprItem, theQRI); return anItem; } } - else { - if (isAngle) { + else + { + if (theIsAngle) + { // Angle & without qualifiers - Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) anItem = + Handle(StepRepr_ReprItemAndPlaneAngleMeasureWithUnit) anItem = new StepRepr_ReprItemAndPlaneAngleMeasureWithUnit(); anItem->Init(aMWU, aReprItem); return anItem; } - else { + else + { // Length & without qualifiers - Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) anItem = + Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) anItem = new StepRepr_ReprItemAndLengthMeasureWithUnit(); anItem->Init(aMWU, aReprItem); return anItem; @@ -2365,30 +2370,30 @@ static Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateDimValue(const Standard } //======================================================================= -//function : WriteShapeAspect +//function : writeShapeAspect //purpose : auxiliary (write Shape_Aspect entity for given shape) //======================================================================= - -Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::WriteShapeAspect (const Handle(XSControl_WorkSession) &WS, - const TDF_Label theLabel, - const TopoDS_Shape theShape, - Handle(StepRepr_RepresentationContext)& theRC, - Handle(StepAP242_GeometricItemSpecificUsage)& theGISU) +Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::writeShapeAspect(const Handle(XSControl_WorkSession)& theWS, + const TDF_Label theLabel, + const TopoDS_Shape theShape, + Handle(StepRepr_RepresentationContext)& theRC, + Handle(StepAP242_GeometricItemSpecificUsage)& theGISU) { // Get working data - const Handle(Interface_InterfaceModel) &Model = WS->Model(); - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); - const Handle(Interface_HGraph) aHGraph = WS->HGraph(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + const Handle(Interface_HGraph) aHGraph = theWS->HGraph(); if (aHGraph.IsNull()) return NULL; Interface_Graph aGraph = aHGraph->Graph(); TopLoc_Location aLoc; TColStd_SequenceOfTransient aSeqRI; - FindEntities( FP, theShape, aLoc, aSeqRI ); - if ( aSeqRI.Length() <= 0 ) { - FP->Messenger()->SendInfo() << "Warning: Cannot find RI for "<DynamicType()->Name()<DynamicType()->Name() << "\n"; return NULL; } @@ -2396,14 +2401,15 @@ Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::WriteShapeAspect (const Hand Handle(StepRepr_RepresentationContext) aRC; Handle(Standard_Transient) anEnt = aSeqRI.Value(1); aPDS = FindPDS(aGraph, anEnt, aRC); - if(aPDS.IsNull()) + if (aPDS.IsNull()) return NULL; theRC = aRC; // Shape_Aspect Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(); Handle(TDataStd_Name) aNameAttr; - if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) { + if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) + { aName = new TCollection_HAsciiString(TCollection_AsciiString(aNameAttr->Get())); Standard_Integer aFirstSpace = aName->Search(" "); if (aFirstSpace != -1) @@ -2422,10 +2428,11 @@ Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::WriteShapeAspect (const Hand Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1); Handle(StepRepr_RepresentationItem) anIdentifiedItem = Handle(StepRepr_RepresentationItem)::DownCast(anEnt); anReprItems->SetValue(1, anIdentifiedItem); - Interface_EntityIterator subs = aGraph.Sharings(aPDS); Handle(StepShape_ShapeDefinitionRepresentation) aSDR; - for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) { - Handle(Standard_Transient) anEntity = subs.Value(); + for (Interface_EntityIterator aSharingIter = aGraph.Sharings(aPDS); + aSharingIter.More() && aSDR.IsNull(); aSharingIter.Next()) + { + Handle(Standard_Transient) anEntity = aSharingIter.Value(); aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity); } if (aSDR.IsNull()) @@ -2433,21 +2440,21 @@ Handle(StepRepr_ShapeAspect) STEPCAFControl_Writer::WriteShapeAspect (const Hand // Set entities to model aGISU->Init(aName, aDescription, aDefinition, aSDR->UsedRepresentation(), anReprItems); - Model->AddWithRefs(aSA); - Model->AddWithRefs(aGISU); + aModel->AddWithRefs(aSA); + aModel->AddWithRefs(aGISU); theGISU = aGISU; return aSA; } //======================================================================= -//function : WritePresentation +//function : writePresentation //purpose : auxiliary (write annotation plane and presentation) //====================================================================== -void STEPCAFControl_Writer::WritePresentation(const Handle(XSControl_WorkSession)& WS, +void STEPCAFControl_Writer::writePresentation(const Handle(XSControl_WorkSession)& theWS, const TopoDS_Shape& thePresentation, const Handle(TCollection_HAsciiString)& thePrsName, - const Standard_Boolean hasSemantic, - const Standard_Boolean hasPlane, + const Standard_Boolean theHasSemantic, + const Standard_Boolean theHasPlane, const gp_Ax2& theAnnotationPlane, const gp_Pnt& theTextPosition, const Handle(Standard_Transient) theDimension) @@ -2455,7 +2462,7 @@ void STEPCAFControl_Writer::WritePresentation(const Handle(XSControl_WorkSession if (thePresentation.IsNull()) return; // Get working data - const Handle(Interface_InterfaceModel) &aModel = WS->Model(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); // Presentation Handle(StepVisual_TessellatedGeometricSet) aGeomSet = STEPCAFControl_GDTProperty::GetTessellation(thePresentation); @@ -2474,7 +2481,7 @@ void STEPCAFControl_Writer::WritePresentation(const Handle(XSControl_WorkSession StepAP242_ItemIdentifiedRepresentationUsageDefinition aDimension; aDimension.SetValue(theDimension); Handle(TCollection_HAsciiString) aDMIAName; - if (hasSemantic) + if (theHasSemantic) aDMIAName = new TCollection_HAsciiString("PMI representation to presentation link"); else aDMIAName = new TCollection_HAsciiString(); @@ -2483,7 +2490,7 @@ void STEPCAFControl_Writer::WritePresentation(const Handle(XSControl_WorkSession aDMIA->Init(aDMIAName, new TCollection_HAsciiString(), aDimension, myGDTPresentationDM, aDCsForDMIA); aModel->AddWithRefs(aDMIA); - if (!hasPlane) + if (!theHasPlane) return; // Annotation plane @@ -2524,22 +2531,22 @@ void STEPCAFControl_Writer::WritePresentation(const Handle(XSControl_WorkSession } //======================================================================= -//function : WriteDatumAP242 -//purpose : auxiliary (write Datum entity for given shape or write all -// necessary entities and link them to already written datum +//function : writeDatumAP242 +//purpose : auxiliary (write Datum entity for given shape or write all +// necessary entities and link them to already written datum // in case of multiple features association) //======================================================================= -Handle(StepDimTol_Datum) STEPCAFControl_Writer::WriteDatumAP242(const Handle(XSControl_WorkSession)& WS, +Handle(StepDimTol_Datum) STEPCAFControl_Writer::writeDatumAP242(const Handle(XSControl_WorkSession)& theWS, const TDF_LabelSequence& theShapeL, const TDF_Label& theDatumL, - const Standard_Boolean isFirstDTarget, + const Standard_Boolean theIsFirstDTarget, const Handle(StepDimTol_Datum) theWrittenDatum) { // Get working data - const Handle(Interface_InterfaceModel) &Model = WS->Model(); - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); - const Handle(Interface_HGraph) aHGraph = WS->HGraph(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + const Handle(Interface_HGraph) aHGraph = theWS->HGraph(); if (aHGraph.IsNull()) return NULL; Interface_Graph aGraph = aHGraph->Graph(); @@ -2551,16 +2558,18 @@ Handle(StepDimTol_Datum) STEPCAFControl_Writer::WriteDatumAP242(const Handle(XSC Handle(StepAP242_GeometricItemSpecificUsage) aGISU; Standard_Integer aSANum = 0, aGISUNum = 0; // Link with datum feature - for (Standard_Integer i = 1; i <= theShapeL.Length(); i++) { + for (TDF_LabelSequence::Iterator aLabelIter(theShapeL); + aLabelIter.More(); aLabelIter.Next()) + { Handle(Standard_Transient) anEnt; - TopoDS_Shape aShape; TopLoc_Location aLoc; TColStd_SequenceOfTransient aSeqRI; - aShape = XCAFDoc_ShapeTool::GetShape(theShapeL.Value(i)); - FindEntities(FP, aShape, aLoc, aSeqRI); - if (aSeqRI.Length() <= 0) { - FP->Messenger()->SendInfo() << "Warning: Cannot find RI for " << aShape.TShape()->DynamicType()->Name() << std::endl; + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aLabelIter.Value()); + FindEntities(aFP, aShape, aLoc, aSeqRI); + if (aSeqRI.Length() <= 0) + { + Message::SendTrace() << "Warning: Cannot find RI for " << aShape.TShape()->DynamicType()->Name() << "\n"; continue; } anEnt = aSeqRI.Value(1); @@ -2568,108 +2577,118 @@ Handle(StepDimTol_Datum) STEPCAFControl_Writer::WriteDatumAP242(const Handle(XSC if (aPDS.IsNull()) continue; - Handle(StepRepr_ShapeAspect) aCurrentSA = WriteShapeAspect(WS, theDatumL, aShape, aRC, aGISU); + Handle(StepRepr_ShapeAspect) aCurrentSA = writeShapeAspect(theWS, theDatumL, aShape, aRC, aGISU); if (aCurrentSA.IsNull()) continue; aSASeq.Append(aCurrentSA); - aSANum = Model->Number(aCurrentSA); - aGISUNum = Model->Number(aGISU); + aSANum = aModel->Number(aCurrentSA); + aGISUNum = aModel->Number(aGISU); } - if (aPDS.IsNull()) { + if (aPDS.IsNull()) + { // Workaround for datums without shape aPDS = myGDTCommonPDS; Interface_EntityIterator aSDRIt = aGraph.Sharings(aPDS); Handle(StepShape_ShapeDefinitionRepresentation) aSDR; for (aSDRIt.Start(); aSDRIt.More() && aSDR.IsNull(); aSDRIt.Next()) aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value()); - if (!aSDR.IsNull()) { + if (!aSDR.IsNull()) + { Handle(StepRepr_Representation) aRepr = aSDR->UsedRepresentation(); if (!aRepr.IsNull()) aRC = aRepr->ContextOfItems(); } } - // Find if datum has datum targets and get common datum attributes Handle(XCAFDoc_Datum) aDatumAttr; - if (!theDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr)) + if (!theDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr)) return NULL; Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject(); if (anObject.IsNull()) return NULL; Standard_Boolean isSimpleDatum = !anObject->IsDatumTarget(); Handle(TCollection_HAsciiString) anIdentifier = anObject->GetName(); - Handle(TCollection_HAsciiString) aTargetId = (anObject->GetDatumTargetNumber() == 0 ? - new TCollection_HAsciiString() : new TCollection_HAsciiString(anObject->GetDatumTargetNumber())); + Handle(TCollection_HAsciiString) aTargetId = (anObject->GetDatumTargetNumber() == 0 ? + new TCollection_HAsciiString() : new TCollection_HAsciiString(anObject->GetDatumTargetNumber())); // If datum type is area, but there is no area in object, write as simple datum if (anObject->GetDatumTargetType() == XCAFDimTolObjects_DatumTargetType_Area && - anObject->GetDatumTarget().IsNull()) + anObject->GetDatumTarget().IsNull()) isSimpleDatum = Standard_True; // Simple datum - if (isSimpleDatum) { - if (aSASeq.Length() == 0) { + if (isSimpleDatum) + { + if (aSASeq.Length() == 0) + { // Create empty datum with name and presentation only Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature(); aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue); aSA = aDF; - Model->AddWithRefs(aDF); + aModel->AddWithRefs(aDF); } - else if (aSASeq.Length() == 1) { + else if (aSASeq.Length() == 1) + { Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature(); aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue); - Model->ReplaceEntity(aSANum, aDF); + aModel->ReplaceEntity(aSANum, aDF); aSA = aDF; StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition; aDefinition.SetValue(aDF); aGISU->SetDefinition(aDefinition); - Model->ReplaceEntity(aGISUNum, aGISU); + aModel->ReplaceEntity(aGISUNum, aGISU); } - else if (aSASeq.Length() > 1) { + else if (aSASeq.Length() > 1) + { Handle(StepRepr_CompShAspAndDatumFeatAndShAsp) aDF = new StepRepr_CompShAspAndDatumFeatAndShAsp(); aDF->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LTrue); - for (Standard_Integer i = 1; i <= aSASeq.Length(); i++) { + for (Standard_Integer i = 1; i <= aSASeq.Length(); i++) + { Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship(); aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aDF, aSASeq.Value(i)); - Model->AddWithRefs(aSAR); + aModel->AddWithRefs(aSAR); } aSA = aDF; - Model->AddWithRefs(aDF); + aModel->AddWithRefs(aDF); } } // Datum with datum targets - else { + else + { XCAFDimTolObjects_DatumTargetType aDatumType = anObject->GetDatumTargetType(); Handle(StepDimTol_DatumTarget) aDatumTarget; // Note: the given way to write such datum type may be incorrect (too little information) - if (aDatumType == XCAFDimTolObjects_DatumTargetType_Area) { + if (aDatumType == XCAFDimTolObjects_DatumTargetType_Area) + { TopoDS_Shape aDTShape = anObject->GetDatumTarget(); Handle(StepAP242_GeometricItemSpecificUsage) anAreaGISU; - Handle(StepRepr_ShapeAspect) anAreaSA = WriteShapeAspect(WS, theDatumL, aDTShape, aRC, anAreaGISU); - aSANum = Model->Number(anAreaSA); - aGISUNum = Model->Number(anAreaGISU); + Handle(StepRepr_ShapeAspect) anAreaSA = writeShapeAspect(theWS, theDatumL, aDTShape, aRC, anAreaGISU); + aSANum = aModel->Number(anAreaSA); + aGISUNum = aModel->Number(anAreaGISU); Handle(StepDimTol_DatumTarget) aDT = new StepDimTol_DatumTarget(); aDT->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString("area"), anAreaSA->OfShape(), - StepData_LTrue, aTargetId); - Model->ReplaceEntity(aSANum, aDT); + StepData_LTrue, aTargetId); + aModel->ReplaceEntity(aSANum, aDT); StepAP242_ItemIdentifiedRepresentationUsageDefinition aDefinition; aDefinition.SetValue(aDT); anAreaGISU->SetDefinition(aDefinition); - Model->ReplaceEntity(aGISUNum, anAreaGISU); + aModel->ReplaceEntity(aGISUNum, anAreaGISU); } - else { + else + { Handle(StepDimTol_PlacedDatumTargetFeature) aPDTF = new StepDimTol_PlacedDatumTargetFeature(); aPDTF->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDatumTargetName(aDatumType), - aPDS, StepData_LTrue, aTargetId); - Model->AddWithRefs(aPDTF); + aPDS, StepData_LTrue, aTargetId); + aModel->AddWithRefs(aPDTF); aDatumTarget = aPDTF; // Datum targets Handle(StepRepr_PropertyDefinition) aPD = new StepRepr_PropertyDefinition(); StepRepr_CharacterizedDefinition aCDefinition; aCDefinition.SetValue(aPDTF); aPD->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCDefinition); - if (anObject->HasDatumTargetParams()) { + if (anObject->HasDatumTargetParams()) + { // write all parameters of datum target Handle(StepShape_ShapeRepresentationWithParameters) aSRWP = new StepShape_ShapeRepresentationWithParameters(); // Common for all datum targets @@ -2680,33 +2699,38 @@ Handle(StepDimTol_Datum) STEPCAFControl_Writer::WriteDatumAP242(const Handle(XSC anA2P3D->SetName(new TCollection_HAsciiString("orientation")); Handle(StepRepr_HArray1OfRepresentationItem) anItems; // Process each datum target type - if (aDatumType == XCAFDimTolObjects_DatumTargetType_Point) { + if (aDatumType == XCAFDimTolObjects_DatumTargetType_Point) + { anItems = new StepRepr_HArray1OfRepresentationItem(1, 1); } - else { + else + { Handle(TCollection_HAsciiString) aTargetValueName; - if (aDatumType == XCAFDimTolObjects_DatumTargetType_Line) { + if (aDatumType == XCAFDimTolObjects_DatumTargetType_Line) + { anItems = new StepRepr_HArray1OfRepresentationItem(1, 2); aTargetValueName = new TCollection_HAsciiString("target length"); } - else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Rectangle) { + else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Rectangle) + { anItems = new StepRepr_HArray1OfRepresentationItem(1, 3); aTargetValueName = new TCollection_HAsciiString("target length"); // Additional value Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetWidth(), - aUnit, new TCollection_HAsciiString("target width"), "POSITIVE_LENGTH_MEASURE", Standard_False); + aUnit, new TCollection_HAsciiString("target width"), "POSITIVE_LENGTH_MEASURE", Standard_False); anItems->SetValue(2, aTargetValue); - Model->AddWithRefs(aTargetValue); + aModel->AddWithRefs(aTargetValue); } - else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Circle) { + else if (aDatumType == XCAFDimTolObjects_DatumTargetType_Circle) + { anItems = new StepRepr_HArray1OfRepresentationItem(1, 2); aTargetValueName = new TCollection_HAsciiString("target diameter"); } // Value Handle(StepRepr_ReprItemAndMeasureWithUnit) aTargetValue = CreateDimValue(anObject->GetDatumTargetLength(), - aUnit, aTargetValueName, "POSITIVE_LENGTH_MEASURE", Standard_False); + aUnit, aTargetValueName, "POSITIVE_LENGTH_MEASURE", Standard_False); anItems->SetValue(1, aTargetValue); - Model->AddWithRefs(aTargetValue); + aModel->AddWithRefs(aTargetValue); } anItems->SetValue(anItems->Length(), anA2P3D); aSRWP->Init(new TCollection_HAsciiString(), anItems, aRC); @@ -2715,71 +2739,76 @@ Handle(StepDimTol_Datum) STEPCAFControl_Writer::WriteDatumAP242(const Handle(XSC StepRepr_RepresentedDefinition aRDefinition; aRDefinition.SetValue(aPD); aSDR->Init(aRDefinition, aSRWP); - Model->AddWithRefs(aPD); - Model->AddWithRefs(aSRWP); - Model->AddWithRefs(aSDR); + aModel->AddWithRefs(aPD); + aModel->AddWithRefs(aSRWP); + aModel->AddWithRefs(aSDR); } } // Link datum target to datum feature // if aSASeq.Length() == 0 nothing to do - if (aSASeq.Length() == 1) { + if (aSASeq.Length() == 1) + { Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship(); aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSASeq.Value(1), aDatumTarget); - Model->AddWithRefs(aFFDTR); + aModel->AddWithRefs(aFFDTR); } - else if (aSASeq.Length() > 1) { + else if (aSASeq.Length() > 1) + { Handle(StepRepr_CompositeShapeAspect) aCompSA = new StepRepr_CompositeShapeAspect(); aCompSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, aSASeq.Value(1)->ProductDefinitional()); - for (Standard_Integer i = 1; i <= aSASeq.Length(); i++) { + for (Standard_Integer i = 1; i <= aSASeq.Length(); i++) + { Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship(); aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCompSA, aSASeq.Value(i)); - Model->AddWithRefs(aSAR); + aModel->AddWithRefs(aSAR); } Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR = new StepRepr_FeatureForDatumTargetRelationship(); aFFDTR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCompSA, aDatumTarget); - Model->AddWithRefs(aFFDTR); + aModel->AddWithRefs(aFFDTR); } aSA = aDatumTarget; } // Datum Handle(StepDimTol_Datum) aDatum = theWrittenDatum; - if (isFirstDTarget) { + if (theIsFirstDTarget) + { aDatum = new StepDimTol_Datum(); aDatum->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aPDS, StepData_LFalse, anIdentifier); - Model->AddWithRefs(aDatum); + aModel->AddWithRefs(aDatum); } // Shape_Aspect_Relationship - if (!aSA.IsNull()) { + if (!aSA.IsNull()) + { Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship(); aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aSA, aDatum); - Model->AddWithRefs(aSAR); + aModel->AddWithRefs(aSAR); } //Annotation plane and Presentation - WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(), - anObject->GetPlane(), anObject->GetPointTextAttach(), aSA); + writePresentation(theWS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(), + anObject->GetPlane(), anObject->GetPointTextAttach(), aSA); return aDatum; } //======================================================================= //function : WriteDimValues -//purpose : auxiliary (write all data for given dimension: values, +//purpose : auxiliary (write all data for given dimension: values, // qualifiers, modifiers, orientation and tolerance class) //====================================================================== -static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, +static void WriteDimValues(const Handle(XSControl_WorkSession)& theWS, const Handle(XCAFDimTolObjects_DimensionObject) theObject, const Handle(StepRepr_RepresentationContext) theRC, const StepShape_DimensionalCharacteristic theDimension) { // Get working data - const Handle(Interface_InterfaceModel) &aModel = WS->Model(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); XCAFDimTolObjects_DimensionModifiersSequence aModifiers = theObject->GetModifiers(); Handle(Standard_Transient) aDim = theDimension.Value(); Standard_Boolean isAngle = aDim->IsKind(STANDARD_TYPE(StepShape_AngularLocation)) || - aDim->IsKind(STANDARD_TYPE(StepShape_AngularSize)); + aDim->IsKind(STANDARD_TYPE(StepShape_AngularSize)); // Unit StepBasic_Unit aUnit = GetUnit(theRC, isAngle); @@ -2811,11 +2840,13 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, if (aLeftNbDigits > 0 || aRightNbDigits > 0) aNbQualifiers++; // With qualifiers - if (aNbQualifiers > 0) { + if (aNbQualifiers > 0) + { Handle(StepShape_QualifiedRepresentationItem) aQRI = new StepShape_QualifiedRepresentationItem(); Handle(StepShape_HArray1OfValueQualifier) aQualifiers = new StepShape_HArray1OfValueQualifier(1, aNbQualifiers); // Type qualifier - if (theObject->HasQualifier() && !isAngle) { + if (theObject->HasQualifier() && !isAngle) + { StepShape_ValueQualifier anItem; Handle(StepShape_TypeQualifier) aType = new StepShape_TypeQualifier(); XCAFDimTolObjects_DimensionQualifier aQualifier = theObject->GetQualifier(); @@ -2825,7 +2856,8 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, aQualifiers->SetValue(1, anItem); } // Number of decimal places - if (aLeftNbDigits > 0 || aRightNbDigits > 0) { + if (aLeftNbDigits > 0 || aRightNbDigits > 0) + { StepShape_ValueQualifier anItem; Handle(StepShape_ValueFormatTypeQualifier) aType = new StepShape_ValueFormatTypeQualifier(); Handle(TCollection_HAsciiString) aFormatType = new TCollection_HAsciiString("NR2 "); @@ -2839,25 +2871,31 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, } // Set qualifiers aQRI->SetQualifiers(aQualifiers); - Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit, - new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle, Standard_True, aQRI); + Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = + CreateDimValue(aNominal, aUnit, + new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle, Standard_True, aQRI); aValues->SetValue(aValIt, anItem); aValIt++; } // Without qualifiers - else { - Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit, - new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle); + else + { + Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = + CreateDimValue(aNominal, aUnit, + new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle); aValues->SetValue(aValIt, anItem); aValIt++; } // Ranges - if (theObject->IsDimWithRange()) { - Handle(StepRepr_ReprItemAndMeasureWithUnit) aLowerItem = CreateDimValue(theObject->GetLowerBound(), aUnit, - new TCollection_HAsciiString("lower limit"), aMeasureName, isAngle); - Handle(StepRepr_ReprItemAndMeasureWithUnit) anUpperItem = CreateDimValue(theObject->GetUpperBound(), aUnit, - new TCollection_HAsciiString("upper limit"), aMeasureName, isAngle); + if (theObject->IsDimWithRange()) + { + Handle(StepRepr_ReprItemAndMeasureWithUnit) aLowerItem = + CreateDimValue(theObject->GetLowerBound(), aUnit, + new TCollection_HAsciiString("lower limit"), aMeasureName, isAngle); + Handle(StepRepr_ReprItemAndMeasureWithUnit) anUpperItem = + CreateDimValue(theObject->GetUpperBound(), aUnit, + new TCollection_HAsciiString("upper limit"), aMeasureName, isAngle); aValues->SetValue(aValIt, aLowerItem); aValIt++; aValues->SetValue(aValIt, anUpperItem); @@ -2865,13 +2903,15 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, } // Modifiers - if (aModifiers.Length() > 0) { + if (aModifiers.Length() > 0) + { Handle(StepRepr_CompoundRepresentationItem) aCompoundRI = new StepRepr_CompoundRepresentationItem(); - Handle (StepRepr_HArray1OfRepresentationItem) aModifItems = + Handle(StepRepr_HArray1OfRepresentationItem) aModifItems = new StepRepr_HArray1OfRepresentationItem(1, aModifiers.Length()); - for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) { + for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) + { XCAFDimTolObjects_DimensionModif aModif = aModifiers.Value(i); - Handle(StepRepr_DescriptiveRepresentationItem) aModifItem = + Handle(StepRepr_DescriptiveRepresentationItem) aModifItem = new StepRepr_DescriptiveRepresentationItem(); aModifItem->Init(new TCollection_HAsciiString(), STEPCAFControl_GDTProperty::GetDimModifierName(aModif)); aModel->AddWithRefs(aModifItem); @@ -2883,7 +2923,8 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, } // Orientation - if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented) { + if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented) + { Handle(StepGeom_Axis2Placement3d) anOrientation = new StepGeom_Axis2Placement3d(); gp_Dir aDir; theObject->GetDirection(aDir); @@ -2901,8 +2942,10 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, } // Descriptions - if (theObject->HasDescriptions()) { - for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) { + if (theObject->HasDescriptions()) + { + for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) + { Handle(StepRepr_DescriptiveRepresentationItem) aDRI = new StepRepr_DescriptiveRepresentationItem(); aDRI->Init(theObject->GetDescriptionName(i), theObject->GetDescription(i)); aValues->SetValue(aValIt, aDRI); @@ -2911,7 +2954,9 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, } for (Standard_Integer i = 1; i <= aValues->Length(); i++) + { aModel->AddWithRefs(aValues->Value(i)); + } // Create resulting Shape_Dimension_Representation Handle(StepShape_ShapeDimensionRepresentation) aSDR = new StepShape_ShapeDimensionRepresentation(); @@ -2922,12 +2967,13 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, aModel->AddWithRefs(aDCR); // Plus_Minus_Tolerance - if (theObject->IsDimWithPlusMinusTolerance()) { + if (theObject->IsDimWithPlusMinusTolerance()) + { Handle(TCollection_HAsciiString) aDummyName = new TCollection_HAsciiString(aMeasureName); aDummyName = aDummyName->SubString(9, aDummyName->Length()); //delete "POSITIVE_" aMeasureName = aDummyName->ToCString(); Standard_Real aLowerTolValue = -theObject->GetLowerTolValue(), - anUpperTolValue = theObject->GetUpperTolValue(); + anUpperTolValue = theObject->GetUpperTolValue(); // Upper Handle(StepBasic_MeasureWithUnit) anUpperMWU = new StepBasic_MeasureWithUnit(); Handle(StepBasic_MeasureValueMember) anUpperValue = new StepBasic_MeasureValueMember(); @@ -2953,7 +2999,8 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, aModel->AddWithRefs(aPlusMinusTol); } // Tolerance class - if (theObject->IsDimWithClassOfTolerance()) { + if (theObject->IsDimWithClassOfTolerance()) + { Standard_Boolean isHole; XCAFDimTolObjects_DimensionFormVariance aFormVariance; XCAFDimTolObjects_DimensionGrade aGrade; @@ -2973,16 +3020,17 @@ static void WriteDimValues(const Handle(XSControl_WorkSession) &WS, //function : WriteDerivedGeometry //purpose : auxiliary (write connection point for dimensions) //====================================================================== -static void WriteDerivedGeometry (const Handle(XSControl_WorkSession) &WS, - const Handle(XCAFDimTolObjects_DimensionObject)& theObject, - const Handle(StepRepr_ConstructiveGeometryRepresentation) theRepr, - Handle(StepRepr_ShapeAspect)& theFirstSA, - Handle(StepRepr_ShapeAspect)& theSecondSA, - NCollection_Vector& thePnts) +static void WriteDerivedGeometry(const Handle(XSControl_WorkSession)& theWS, + const Handle(XCAFDimTolObjects_DimensionObject)& theObject, + const Handle(StepRepr_ConstructiveGeometryRepresentation) theRepr, + Handle(StepRepr_ShapeAspect)& theFirstSA, + Handle(StepRepr_ShapeAspect)& theSecondSA, + NCollection_Vector& thePnts) { - const Handle(Interface_InterfaceModel) &aModel = WS->Model(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); // First point - if (theObject->HasPoint()) { + if (theObject->HasPoint()) + { GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint()); Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value(); thePnts.Append(aPoint); @@ -3000,9 +3048,10 @@ static void WriteDerivedGeometry (const Handle(XSControl_WorkSession) &WS, aModel->AddWithRefs(aGISU); aModel->AddWithRefs(aSADR); } - + // Second point (for locations) - if (theObject->HasPoint2()) { + if (theObject->HasPoint2()) + { GeomToStep_MakeCartesianPoint aPointMaker(theObject->GetPoint2()); Handle(StepGeom_CartesianPoint) aPoint = aPointMaker.Value(); thePnts.Append(aPoint); @@ -3027,20 +3076,20 @@ static void WriteDerivedGeometry (const Handle(XSControl_WorkSession) &WS, //purpose : auxiliary (write Write datum system for given // geometric_tolerance) //====================================================================== -static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(XSControl_WorkSession) &WS, +static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(XSControl_WorkSession)& theWS, const TDF_Label theGeomTolL, const TDF_LabelSequence theDatumSeq, const STEPConstruct_DataMapOfAsciiStringTransient theDatumMap, const Handle(StepRepr_RepresentationContext)& theRC) { // Get working data - const Handle(Interface_InterfaceModel) &Model = WS->Model(); - const Handle(Interface_HGraph) aHGraph = WS->HGraph(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); + const Handle(Interface_HGraph) aHGraph = theWS->HGraph(); if (aHGraph.IsNull()) return NULL; Interface_Graph aGraph = aHGraph->Graph(); Handle(XCAFDoc_GeomTolerance) aGTAttr; - if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr)) + if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr)) return NULL; Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject(); if (anObject.IsNull()) @@ -3051,9 +3100,12 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const XCAFDimTolObjects_DatumObjectSequence aDatums; Standard_Integer aMaxDatumNum = 0; - for (Standard_Integer i = 1; i <= theDatumSeq.Length(); i++) { + + for (TDF_LabelSequence::Iterator aDatumIter(theDatumSeq); + aDatumIter.More(); aDatumIter.Next()) + { Handle(XCAFDoc_Datum) aDatumAttr; - if (!theDatumSeq.Value(i).FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr)) + if (!aDatumIter.Value().FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr)) continue; Handle(XCAFDimTolObjects_DatumObject) aDatumObj = aDatumAttr->GetObject(); if (aDatumObj.IsNull()) @@ -3068,27 +3120,32 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const new StepDimTol_HArray1OfDatumReferenceCompartment(1, aMaxDatumNum); // Auxiliary datum to initialize attributes in Datum_System Handle(StepDimTol_Datum) aFirstDatum; - Standard_Integer aConstituentsNum = 0; - for (Standard_Integer i = 1; i <= aMaxDatumNum; i++) { + for (Standard_Integer aConstituentsNum = 1; + aConstituentsNum <= aMaxDatumNum; aConstituentsNum++) + { // Collect datums with i-th position XCAFDimTolObjects_DatumObjectSequence aDatumSeqPos; - for (Standard_Integer j = 1; j <= aDatums.Length(); j++) - if (aDatums.Value(j)->GetPosition() == i) - aDatumSeqPos.Append(aDatums.Value(j)); + for (XCAFDimTolObjects_DatumObjectSequence::Iterator aDatumIter(aDatums); + aDatumIter.More(); aDatumIter.Next()) + { + if (aDatumIter.Value()->GetPosition() == aConstituentsNum) + { + aDatumSeqPos.Append(aDatumIter.Value()); + } + } if (aDatumSeqPos.Length() < 1) continue; - - aConstituentsNum++; // Initialize Datum_Reference_Compartment StepDimTol_DatumOrCommonDatum aDatumRef; Handle(StepDimTol_DatumReferenceCompartment) aCompartment = new StepDimTol_DatumReferenceCompartment(); Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers; - if (aDatumSeqPos.Length() == 1) { + if (aDatumSeqPos.Length() == 1) + { // Datum entity Handle(Standard_Transient) aFDValue; if (theDatumMap.Find(aDatumSeqPos.Value(1)->GetName()->String(), aFDValue) && !aFDValue.IsNull()) - aFirstDatum = Handle(StepDimTol_Datum)::DownCast (aFDValue); + aFirstDatum = Handle(StepDimTol_Datum)::DownCast(aFDValue); aDatumRef.SetValue(aFirstDatum); // Modifiers XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(1)->GetModifiers(); @@ -3097,81 +3154,101 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const aDatumSeqPos.Value(1)->GetModifierWithValue(aModifWithVal, aValue); aModifiers = STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit); // Add Datum_Reference_Modifier_With_Value - if (!aModifiers.IsNull()) { - Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV = + if (!aModifiers.IsNull()) + { + Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV = aModifiers->Value(aModifiers->Length()).DatumReferenceModifierWithValue(); - if (!aDRMWV.IsNull()) { - Model->AddWithRefs(aDRMWV); + if (!aDRMWV.IsNull()) + { + aModel->AddWithRefs(aDRMWV); } } } - else { - Handle(StepDimTol_HArray1OfDatumReferenceElement) aCommonDatumList = new StepDimTol_HArray1OfDatumReferenceElement(1, aDatumSeqPos.Length()); - for (Standard_Integer j = 1; j <= aDatumSeqPos.Length(); j++) { + else + { + Standard_Integer aSetInd = 1; + Handle(StepDimTol_HArray1OfDatumReferenceElement) aCommonDatumList = + new StepDimTol_HArray1OfDatumReferenceElement(1, aDatumSeqPos.Length()); + for (XCAFDimTolObjects_DatumObjectSequence::Iterator aDatumIter(aDatumSeqPos); + aDatumIter.More(); aDatumIter.Next()) + { // Datum entity + const Handle(XCAFDimTolObjects_DatumObject)& aDatumObj = aDatumIter.Value(); Handle(StepDimTol_Datum) aDatum; Handle(Standard_Transient) aDValue; - if (theDatumMap.Find(aDatumSeqPos.Value(j)->GetName()->String(), aDValue)) - aDatum = Handle(StepDimTol_Datum)::DownCast (aDValue); + if (theDatumMap.Find(aDatumObj->GetName()->String(), aDValue)) + aDatum = Handle(StepDimTol_Datum)::DownCast(aDValue); StepDimTol_DatumOrCommonDatum anElemDatumRef; anElemDatumRef.SetValue(aDatum); if (aFirstDatum.IsNull()) aFirstDatum = aDatum; // Modifiers - XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumSeqPos.Value(j)->GetModifiers(); + XCAFDimTolObjects_DatumModifiersSequence aSimpleModifiers = aDatumObj->GetModifiers(); XCAFDimTolObjects_DatumModifWithValue aModifWithVal; Standard_Real aValue = 0; - aDatumSeqPos.Value(j)->GetModifierWithValue(aModifWithVal, aValue); + aDatumObj->GetModifierWithValue(aModifWithVal, aValue); Handle(StepDimTol_HArray1OfDatumReferenceModifier) anElemModifiers = STEPCAFControl_GDTProperty::GetDatumRefModifiers(aSimpleModifiers, aModifWithVal, aValue, aUnit); // Add Datum_Reference_Modifier_With_Value - if (!anElemModifiers.IsNull()) { - Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV = + if (!anElemModifiers.IsNull()) + { + Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV = anElemModifiers->Value(anElemModifiers->Length()).DatumReferenceModifierWithValue(); - if (!aDRMWV.IsNull()) { - Model->AddWithRefs(aDRMWV); + if (!aDRMWV.IsNull()) + { + aModel->AddWithRefs(aDRMWV); } } // Datum_Reference_Element Handle(StepDimTol_DatumReferenceElement) anElement = new StepDimTol_DatumReferenceElement(); anElement->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aDatum->OfShape(), - aDatum->ProductDefinitional(), anElemDatumRef, !anElemModifiers.IsNull(), anElemModifiers); - Model->AddWithRefs(anElement); - aCommonDatumList->SetValue(j, anElement); + aDatum->ProductDefinitional(), anElemDatumRef, !anElemModifiers.IsNull(), anElemModifiers); + aModel->AddWithRefs(anElement); + aCommonDatumList->SetValue(aSetInd++, anElement); } aDatumRef.SetValue(aCommonDatumList); } aCompartment->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(), - aFirstDatum->ProductDefinitional(), aDatumRef, !aModifiers.IsNull(), aModifiers); - Model->AddWithRefs(aCompartment); + aFirstDatum->ProductDefinitional(), aDatumRef, !aModifiers.IsNull(), aModifiers); + aModel->AddWithRefs(aCompartment); aConstituents->SetValue(aConstituentsNum, aCompartment); } // Remove null elements from aConstituents Standard_Integer aNbConstituents = 0; - for (Standard_Integer i = 1; i <= aConstituents->Length(); i++) - if (!aConstituents->Value(i).IsNull()) + for (StepDimTol_HArray1OfDatumReferenceCompartment::Iterator aConstituentIter(aConstituents->Array1()); + aConstituentIter.More(); aConstituentIter.Next()) + { + if (!aConstituentIter.Value().IsNull()) + { aNbConstituents++; + } + } Handle(StepDimTol_HArray1OfDatumReferenceCompartment) aResConstituents = new StepDimTol_HArray1OfDatumReferenceCompartment(1, aNbConstituents); Standard_Integer aConstituentsIt = 0; - for (Standard_Integer i = 1; i <= aConstituents->Length(); i++) - if (!aConstituents->Value(i).IsNull()) { + for (StepDimTol_HArray1OfDatumReferenceCompartment::Iterator aConstituentIter(aConstituents->Array1()); + aConstituentIter.More(); aConstituentIter.Next()) + { + if (!aConstituentIter.Value().IsNull()) + { aConstituentsIt++; - aResConstituents->SetValue(aConstituentsIt, aConstituents->Value(i)); + aResConstituents->SetValue(aConstituentsIt, aConstituentIter.Value()); } + } Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem; Handle(StepDimTol_DatumSystem) aDS = new StepDimTol_DatumSystem(); aDS->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), aFirstDatum->OfShape(), - aFirstDatum->ProductDefinitional(), aResConstituents); - Model->AddWithRefs(aDS); + aFirstDatum->ProductDefinitional(), aResConstituents); + aModel->AddWithRefs(aDS); StepDimTol_DatumSystemOrReference anArrayValue; anArrayValue.SetValue(aDS); aDatumSystem = new StepDimTol_HArray1OfDatumSystemOrReference(1, 1); aDatumSystem->SetValue(1, anArrayValue); // Axis - if (anObject->HasAxis()) { + if (anObject->HasAxis()) + { GeomToStep_MakeAxis2Placement3d anAxisMaker(anObject->GetAxis()); Handle(StepGeom_Axis2Placement3d) anAxis = anAxisMaker.Value(); anAxis->SetName(new TCollection_HAsciiString("orientation")); @@ -3181,46 +3258,48 @@ static Handle(StepDimTol_HArray1OfDatumSystemOrReference) WriteDatumSystem(const Handle(StepRepr_HArray1OfRepresentationItem) anReprItems = new StepRepr_HArray1OfRepresentationItem(1, 1); Handle(StepRepr_RepresentationItem) anIdentifiedItem = anAxis; anReprItems->SetValue(1, anIdentifiedItem); - Interface_EntityIterator subs = aGraph.Sharings(aFirstDatum->OfShape()); Handle(StepShape_ShapeDefinitionRepresentation) aSDR; - for (subs.Start(); subs.More() && aSDR.IsNull(); subs.Next()) { - Handle(Standard_Transient) anEntity = subs.Value(); - aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anEntity); + for (Interface_EntityIterator aSharingsIter = aGraph.Sharings(aFirstDatum->OfShape()); + aSharingsIter.More() && aSDR.IsNull(); aSharingsIter.Next()) + { + aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSharingsIter.Value()); } if (aSDR.IsNull()) return aDatumSystem; - + aGISU->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), - aDefinition, aSDR->UsedRepresentation(), anReprItems); - Model->AddWithRefs(anAxis); - Model->AddWithRefs(aGISU); + aDefinition, aSDR->UsedRepresentation(), anReprItems); + aModel->AddWithRefs(anAxis); + aModel->AddWithRefs(aGISU); } return aDatumSystem; } //======================================================================= -//function : WriteToleranceZone +//function : writeToleranceZone //purpose : auxiliary (write tolerace zones) //======================================================================= -void STEPCAFControl_Writer::WriteToleranceZone (const Handle(XSControl_WorkSession) &WS, - const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject, - const Handle(StepDimTol_GeometricTolerance)& theEntity, - const Handle(StepRepr_RepresentationContext)& theRC) +void STEPCAFControl_Writer::writeToleranceZone(const Handle(XSControl_WorkSession)& theWS, + const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject, + const Handle(StepDimTol_GeometricTolerance)& theEntity, + const Handle(StepRepr_RepresentationContext)& theRC) { // Get working data - const Handle(Interface_InterfaceModel) &Model = WS->Model(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); if (theEntity.IsNull() || theObject.IsNull()) return; // Return if there is no tolerance zones if (theObject->GetTypeOfValue() == XCAFDimTolObjects_GeomToleranceTypeValue_None && theObject->GetZoneModifier() != XCAFDimTolObjects_GeomToleranceZoneModif_Runout) + { return; + } // Create Tolerance_Zone Handle(StepDimTol_ToleranceZoneForm) aForm = new StepDimTol_ToleranceZoneForm(); - Model->AddWithRefs(aForm); + aModel->AddWithRefs(aForm); aForm->Init(STEPCAFControl_GDTProperty::GetTolValueType(theObject->GetTypeOfValue())); Handle(StepDimTol_HArray1OfToleranceZoneTarget) aZoneTargetArray = new StepDimTol_HArray1OfToleranceZoneTarget(1, 1); StepDimTol_ToleranceZoneTarget aTarget; @@ -3228,9 +3307,9 @@ void STEPCAFControl_Writer::WriteToleranceZone (const Handle(XSControl_WorkSessi aZoneTargetArray->SetValue(1, aTarget); Handle(StepDimTol_ToleranceZone) aZone = new StepDimTol_ToleranceZone(); aZone->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), - theEntity->TolerancedShapeAspect().ShapeAspect()->OfShape(), StepData_LFalse, - aZoneTargetArray, aForm); - Model->AddWithRefs(aZone); + theEntity->TolerancedShapeAspect().ShapeAspect()->OfShape(), StepData_LFalse, + aZoneTargetArray, aForm); + aModel->AddWithRefs(aZone); // Runout_Tolerance_Zone Handle(StepBasic_PlaneAngleMeasureWithUnit) aPAMWU = new StepBasic_PlaneAngleMeasureWithUnit(); @@ -3242,26 +3321,26 @@ void STEPCAFControl_Writer::WriteToleranceZone (const Handle(XSControl_WorkSessi anOrientation->Init(aPAMWU); Handle(StepDimTol_RunoutZoneDefinition) aDefinition = new StepDimTol_RunoutZoneDefinition(); aDefinition->Init(aZone, NULL, anOrientation); - Model->AddWithRefs(aDefinition); - Model->AddWithRefs(anOrientation); - Model->AddWithRefs(aPAMWU); + aModel->AddWithRefs(aDefinition); + aModel->AddWithRefs(anOrientation); + aModel->AddWithRefs(aPAMWU); } //======================================================================= -//function : WriteGeomTolerance +//function : writeGeomTolerance //purpose : auxiliary (write Geometric_Tolerance entity for given shapes, // label and datum system) //====================================================================== -void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence& theShapeSeqL, - const TDF_Label& theGeomTolL, - const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem, - const Handle(StepRepr_RepresentationContext)& theRC) +void STEPCAFControl_Writer::writeGeomTolerance(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theShapeSeqL, + const TDF_Label& theGeomTolL, + const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem, + const Handle(StepRepr_RepresentationContext)& theRC) { // Get working data - const Handle(Interface_InterfaceModel) &Model = WS->Model(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); Handle(XCAFDoc_GeomTolerance) aGTAttr; - if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr)) + if (!theGeomTolL.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGTAttr)) return; Handle(XCAFDimTolObjects_GeomToleranceObject) anObject = aGTAttr->GetObject(); if (anObject.IsNull()) @@ -3274,32 +3353,37 @@ void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSessi aValueMember->SetName("LENGTH_MEASURE"); aValueMember->SetReal(anObject->GetValue()); aLMWU->Init(aValueMember, aUnit); - Model->AddWithRefs(aLMWU); + aModel->AddWithRefs(aLMWU); // Geometric_Tolerance target Handle(StepRepr_ShapeAspect) aMainSA; Handle(StepRepr_RepresentationContext) dummyRC; Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU; - if (theShapeSeqL.Length() == 1) { + if (theShapeSeqL.Length() == 1) + { TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(1)); - aMainSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU); - Model->AddWithRefs(aMainSA); + aMainSA = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU); + aModel->AddWithRefs(aMainSA); } - else { + else + { Handle(StepRepr_CompositeShapeAspect) aCSA; - for (Standard_Integer i = 1; i <= theShapeSeqL.Length(); i++) { - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theShapeSeqL.Value(i)); - Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, theGeomTolL, aShape, dummyRC, dummyGISU); + for (TDF_LabelSequence::Iterator aShIter(theShapeSeqL); + aShIter.More(); aShIter.Next()) + { + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShIter.Value()); + Handle(StepRepr_ShapeAspect) aSA = writeShapeAspect(theWS, theGeomTolL, aShape, dummyRC, dummyGISU); if (aSA.IsNull()) continue; - if (aCSA.IsNull()) { + if (aCSA.IsNull()) + { aCSA = new StepRepr_CompositeShapeAspect(); aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional()); - Model->AddWithRefs(aCSA); + aModel->AddWithRefs(aCSA); } Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship(); aSAR->Init(new TCollection_HAsciiString(), Standard_False, NULL, aCSA, aSA); - Model->AddWithRefs(aSAR); + aModel->AddWithRefs(aSAR); } aMainSA = aCSA; } @@ -3307,8 +3391,8 @@ void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSessi aGTTarget.SetValue(aMainSA); Standard_Boolean isWithModif = Standard_False, - isWithDatRef = Standard_False, - isWithMaxTol = Standard_False; + isWithDatRef = Standard_False, + isWithMaxTol = Standard_False; // Modifiers // Simple modifiers XCAFDimTolObjects_GeomToleranceModifiersSequence aModifiers = anObject->GetModifiers(); @@ -3316,39 +3400,50 @@ void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSessi Handle(StepBasic_LengthMeasureWithUnit) aMaxLMWU; Standard_Integer aModifNb = aModifiers.Length(); if (anObject->GetMaterialRequirementModifier() != XCAFDimTolObjects_GeomToleranceMatReqModif_None) - aModifNb++; + aModifNb++; for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) + { if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around || aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over) - aModifNb--; - if (aModifNb > 0) { + { + aModifNb--; + } + } + if (aModifNb > 0) + { isWithModif = Standard_True; aModifArray = new StepDimTol_HArray1OfGeometricToleranceModifier(1, aModifNb); Standard_Integer k = 1; - for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) { + for (Standard_Integer i = 1; i <= aModifiers.Length(); i++) + { if (aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Around || - aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over) + aModifiers.Value(i) == XCAFDimTolObjects_GeomToleranceModif_All_Over) + { continue; - StepDimTol_GeometricToleranceModifier aModif = + } + StepDimTol_GeometricToleranceModifier aModif = STEPCAFControl_GDTProperty::GetGeomToleranceModifier(aModifiers.Value(i)); aModifArray->SetValue(k, aModif); k++; } - if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_L) { + if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_L) + { aModifArray->SetValue(aModifNb, StepDimTol_GTMLeastMaterialRequirement); } - else if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_M) { + else if (anObject->GetMaterialRequirementModifier() == XCAFDimTolObjects_GeomToleranceMatReqModif_M) + { aModifArray->SetValue(aModifNb, StepDimTol_GTMMaximumMaterialRequirement); } // Modifier with value - if (anObject->GetMaxValueModifier() != 0) { + if (anObject->GetMaxValueModifier() != 0) + { isWithMaxTol = Standard_True; aMaxLMWU = new StepBasic_LengthMeasureWithUnit(); Handle(StepBasic_MeasureValueMember) aModifierValueMember = new StepBasic_MeasureValueMember(); aModifierValueMember->SetName("LENGTH_MEASURE"); aModifierValueMember->SetReal(anObject->GetMaxValueModifier()); aMaxLMWU->Init(aModifierValueMember, aUnit); - Model->AddWithRefs(aMaxLMWU); + aModel->AddWithRefs(aMaxLMWU); } } @@ -3357,29 +3452,33 @@ void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSessi // Collect all attributes Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(), - aDescription = new TCollection_HAsciiString(); - Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR = + aDescription = new TCollection_HAsciiString(); + Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR = new StepDimTol_GeometricToleranceWithDatumReference(); aGTWDR->SetDatumSystem(theDatumSystem); - Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM = + Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM = new StepDimTol_GeometricToleranceWithModifiers(); aGTWM->SetModifiers(aModifArray); - StepDimTol_GeometricToleranceType aType = + StepDimTol_GeometricToleranceType aType = STEPCAFControl_GDTProperty::GetGeomToleranceType(anObject->GetType()); // Init and write necessary subtype of Geometric_Tolerance entity Handle(StepDimTol_GeometricTolerance) aGeomTol; - if (isWithModif) { - if (isWithMaxTol) { - if (isWithDatRef) { - // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference & - //Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers + if (isWithModif) + { + if (isWithMaxTol) + { + if (isWithDatRef) + { + // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference & + // Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol) aResult = new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol(); aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aMaxLMWU, aType); aGeomTol = aResult; } - else { + else + { // Geometric_Tolerance & Geometric_Tolerance_With_Maximum_Tolerance & Geometric_Tolerance_With_Modifiers Handle(StepDimTol_GeoTolAndGeoTolWthMaxTol) aResult = new StepDimTol_GeoTolAndGeoTolWthMaxTol(); @@ -3387,15 +3486,18 @@ void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSessi aGeomTol = aResult; } } - else { - if (isWithDatRef) { + else + { + if (isWithDatRef) + { // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference & Geometric_Tolerance_With_Modifiers Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) aResult = new StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod(); aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aGTWM, aType); aGeomTol = aResult; } - else { + else + { // Geometric_Tolerance & Geometric_Tolerance_With_Modifiers Handle(StepDimTol_GeoTolAndGeoTolWthMod) aResult = new StepDimTol_GeoTolAndGeoTolWthMod(); @@ -3404,359 +3506,401 @@ void STEPCAFControl_Writer::WriteGeomTolerance (const Handle(XSControl_WorkSessi } } } - else { - if (isWithDatRef) { + else + { + if (isWithDatRef) + { // Geometric_Tolerance & Geometric_Tolerance_With_Datum_Reference Handle(StepDimTol_GeoTolAndGeoTolWthDatRef) aResult = - new StepDimTol_GeoTolAndGeoTolWthDatRef(); - aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aType); - aGeomTol = aResult; + new StepDimTol_GeoTolAndGeoTolWthDatRef(); + aResult->Init(aName, aDescription, aLMWU, aGTTarget, aGTWDR, aType); + aGeomTol = aResult; } - else { + else + { // Geometric_Tolerance - Handle(StepDimTol_GeometricTolerance) aResult = + Handle(StepDimTol_GeometricTolerance) aResult = STEPCAFControl_GDTProperty::GetGeomTolerance(anObject->GetType()); - if (!aResult.IsNull()) { + if (!aResult.IsNull()) + { aResult->Init(aName, aDescription, aLMWU, aGTTarget); aGeomTol = aResult; } } } - Model->AddWithRefs(aGeomTol); - WriteToleranceZone(WS, anObject, aGeomTol, theRC); + aModel->AddWithRefs(aGeomTol); + writeToleranceZone(theWS, anObject, aGeomTol, theRC); //Annotation plane and Presentation - WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(), - anObject->GetPlane(), anObject->GetPointTextAttach(), aGeomTol); + writePresentation(theWS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(), + anObject->GetPlane(), anObject->GetPointTextAttach(), aGeomTol); } //======================================================================= -//function : WriteDGTs -//purpose : +//function : writeDGTs +//purpose : //======================================================================= -Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels ) const +Standard_Boolean STEPCAFControl_Writer::writeDGTs(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const { - - if ( labels.Length() <=0 ) return Standard_False; - - // get working data - const Handle(Interface_InterfaceModel) &Model = WS->Model(); - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); - const Handle(Interface_HGraph) aHGraph = WS->HGraph(); - if(aHGraph.IsNull()) + if (theLabels.IsEmpty()) + return Standard_False; + + // get working data + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); + + const Handle(Interface_HGraph) aHGraph = theWS->HGraph(); + if (aHGraph.IsNull()) return Standard_False; Interface_Graph aGraph = aHGraph->Graph(); - Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) ); - if(DGTTool.IsNull() ) return Standard_False; + STEPConstruct_DataMapOfAsciiStringTransient aDatumMap; - TDF_LabelSequence DGTLabels; + TDF_LabelSequence aDGTLabels; + // Iterate on requested shapes collect Tools + for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(aLabel); + TDF_LabelSequence aDGTLS; + aDGTTool->GetDatumLabels(aDGTLS); + aDGTLabels.Append(aDGTLS); + } - STEPConstruct_DataMapOfAsciiStringTransient DatumMap; + if (aDGTLabels.IsEmpty()) + return Standard_False; - // write Datums - DGTLabels.Clear(); - DGTTool->GetDatumLabels(DGTLabels); - if(DGTLabels.Length()<=0) return Standard_False; - Standard_Integer i; - for(i=1; i<=DGTLabels.Length(); i++) { - TDF_Label DatumL = DGTLabels.Value(i); - TDF_LabelSequence ShapeL; + for (TDF_LabelSequence::Iterator aDGTIter(aDGTLabels); + aDGTIter.More(); aDGTIter.Next()) + { + const TDF_Label& aDatumL = aDGTIter.Value(); + TDF_LabelSequence aShapeL; TDF_LabelSequence aNullSeq; - if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL,aNullSeq)) continue; + if (!XCAFDoc_DimTolTool::GetRefShapeLabel(aDatumL, aShapeL, aNullSeq)) continue; // find target shape - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1)); - TopLoc_Location Loc; - TColStd_SequenceOfTransient seqRI; - FindEntities( FP, aShape, Loc, seqRI ); - if ( seqRI.Length() <= 0 ) { - FP->Messenger()->SendInfo() << "Warning: Cannot find RI for "<DynamicType()->Name()<DynamicType()->Name() << "\n"; continue; } - Handle(StepRepr_ProductDefinitionShape) PDS; - Handle(StepRepr_RepresentationContext) RC; - Handle(Standard_Transient) ent = seqRI.Value(1); - Handle(StepShape_AdvancedFace) AF; - Handle(StepShape_EdgeCurve) EC; - FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC); - if(PDS.IsNull()) continue; - //std::cout<<"Model->Number(PDS)="<Number(PDS)<GetName(); - Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification(); - Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription(); + Handle(StepRepr_ProductDefinitionShape) aPDS; + Handle(StepRepr_RepresentationContext) aRC; + Handle(Standard_Transient) anEnt = aSeqRI.Value(1); + Handle(StepShape_AdvancedFace) anAF; + Handle(StepShape_EdgeCurve) anEC; + FindPDSforDGT(aGraph, anEnt, aPDS, aRC, anAF, anEC); + if (aPDS.IsNull()) + continue; + Handle(XCAFDoc_Datum) aDatumAttr; + if (!aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr)) + continue; + Handle(TCollection_HAsciiString) aName = aDatumAttr->GetName(); + Handle(TCollection_HAsciiString) anIdentification = aDatumAttr->GetIdentification(); + Handle(TCollection_HAsciiString) aDescription = aDatumAttr->GetDescription(); if (aDescription.IsNull()) { aDescription = new TCollection_HAsciiString(); } - Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature; + Handle(StepDimTol_DatumFeature) aDF = new StepDimTol_DatumFeature; Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum; - DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue); - Model->AddWithRefs(DF); - aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification); - Model->AddWithRefs(aDatum); - Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship; - SAR->SetName(aName); - SAR->SetRelatingShapeAspect(DF); - SAR->SetRelatedShapeAspect(aDatum); - Model->AddWithRefs(SAR); + aDF->Init(aName, new TCollection_HAsciiString, aPDS, StepData_LTrue); + aModel->AddWithRefs(aDF); + aDatum->Init(aName, new TCollection_HAsciiString, aPDS, StepData_LFalse, anIdentification); + aModel->AddWithRefs(aDatum); + Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship; + aSAR->SetName(aName); + aSAR->SetRelatingShapeAspect(aDF); + aSAR->SetRelatedShapeAspect(aDatum); + aModel->AddWithRefs(aSAR); // write chain for DatumFeature - StepRepr_CharacterizedDefinition CD; - CD.SetValue(DF); - Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition; - PropD->Init(aName,Standard_True,aDescription,CD); - Model->AddWithRefs(PropD); - StepRepr_RepresentedDefinition RD; - RD.SetValue(PropD); - Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation; - Handle(StepRepr_HArray1OfRepresentationItem) HARI = - new StepRepr_HArray1OfRepresentationItem(1,1); - HARI->SetValue(1,AF); - SR->Init(aName,HARI,RC); - Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation; - SDR->Init(RD,SR); - Model->AddWithRefs(SDR); - // write chain for Datum - StepRepr_CharacterizedDefinition CD1; - CD1.SetValue(aDatum); - Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition; - PropD1->Init(aName,Standard_True,aDescription,CD1); - Model->AddWithRefs(PropD1); - StepRepr_RepresentedDefinition RD1; - RD1.SetValue(PropD1); - Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation; - Handle(StepRepr_HArray1OfRepresentationItem) HARI1 = - new StepRepr_HArray1OfRepresentationItem(1,1); - HARI1->SetValue(1,AF->FaceGeometry()); - SR1->Init(aName,HARI1,RC); - Model->AddWithRefs(SR1); - Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation; - SDR1->Init(RD1,SR1); - Model->AddWithRefs(SDR1); + StepRepr_CharacterizedDefinition aCD; + aCD.SetValue(aDF); + Handle(StepRepr_PropertyDefinition) aPropD = new StepRepr_PropertyDefinition; + aPropD->Init(aName, Standard_True, aDescription, aCD); + aModel->AddWithRefs(aPropD); + StepRepr_RepresentedDefinition aRD; + aRD.SetValue(aPropD); + Handle(StepShape_ShapeRepresentation) aSR = new StepShape_ShapeRepresentation; + Handle(StepRepr_HArray1OfRepresentationItem) aHARI = + new StepRepr_HArray1OfRepresentationItem(1, 1); + aHARI->SetValue(1, anAF); + aSR->Init(aName, aHARI, aRC); + Handle(StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation; + aSDR->Init(aRD, aSR); + aModel->AddWithRefs(aSDR); + // write chain for Datum + StepRepr_CharacterizedDefinition aCD1; + aCD1.SetValue(aDatum); + Handle(StepRepr_PropertyDefinition) aPropD1 = new StepRepr_PropertyDefinition; + aPropD1->Init(aName, Standard_True, aDescription, aCD1); + aModel->AddWithRefs(aPropD1); + StepRepr_RepresentedDefinition aRD1; + aRD1.SetValue(aPropD1); + Handle(StepShape_ShapeRepresentation) aSR1 = new StepShape_ShapeRepresentation; + Handle(StepRepr_HArray1OfRepresentationItem) aHARI1 = + new StepRepr_HArray1OfRepresentationItem(1, 1); + aHARI1->SetValue(1, anAF->FaceGeometry()); + aSR1->Init(aName, aHARI1, aRC); + aModel->AddWithRefs(aSR1); + Handle(StepShape_ShapeDefinitionRepresentation) aSDR1 = new StepShape_ShapeDefinitionRepresentation; + aSDR1->Init(aRD1, aSR1); + aModel->AddWithRefs(aSDR1); // add created Datum into Map - TCollection_AsciiString stmp(aName->ToCString()); - stmp.AssignCat(aDescription->ToCString()); - stmp.AssignCat(anIdentification->ToCString()); - DatumMap.Bind(stmp,aDatum); + TCollection_AsciiString aStmp(aName->ToCString()); + aStmp.AssignCat(aDescription->ToCString()); + aStmp.AssignCat(anIdentification->ToCString()); + aDatumMap.Bind(aStmp, aDatum); } // write Tolerances and Dimensions - DGTLabels.Clear(); - DGTTool->GetDimTolLabels(DGTLabels); - if(DGTLabels.Length()<=0) return Standard_False; - for(i=1; i<=DGTLabels.Length(); i++) { - TDF_Label DimTolL = DGTLabels.Value(i); - TDF_LabelSequence ShapeL; + aDGTLabels.Clear(); + // Iterate on requested shapes collect Tools + for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(aLabel); + TDF_LabelSequence aaDGTLS; + aDGTTool->GetDimTolLabels(aDGTLabels); + aDGTLabels.Append(aaDGTLS); + } + + if (aDGTLabels.IsEmpty()) + return Standard_False; + for (TDF_LabelSequence::Iterator aDGTIter(aDGTLabels); + aDGTIter.More(); aDGTIter.Next()) + { + const TDF_Label& aDimTolL = aDGTIter.Value(); + TDF_LabelSequence aShapeL; TDF_LabelSequence aNullSeq; - if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL,aNullSeq)) continue; + if (!XCAFDoc_DimTolTool::GetRefShapeLabel(aDimTolL, aShapeL, aNullSeq)) + continue; // find target shape - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL.Value(1)); - TopLoc_Location Loc; + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShapeL.Value(1)); + TopLoc_Location aLoc; TColStd_SequenceOfTransient seqRI; - FindEntities( FP, aShape, Loc, seqRI ); - if ( seqRI.Length() <= 0 ) { - FP->Messenger()->SendInfo() << "Warning: Cannot find RI for "<DynamicType()->Name()<DynamicType()->Name() << "\n"; continue; } - Handle(StepRepr_ProductDefinitionShape) PDS; - Handle(StepRepr_RepresentationContext) RC; - Handle(Standard_Transient) ent = seqRI.Value(1); - Handle(StepShape_AdvancedFace) AF; - Handle(StepShape_EdgeCurve) EC; - FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC); - if(PDS.IsNull()) continue; - //std::cout<<"Model->Number(PDS)="<Number(PDS)<GetKind(); - Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal(); - Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName(); - Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription(); + Handle(XCAFDoc_DimTol) aDimTolAttr; + if (!aDimTolL.FindAttribute(XCAFDoc_DimTol::GetID(), aDimTolAttr)) + continue; + Standard_Integer aKind = aDimTolAttr->GetKind(); + Handle(TColStd_HArray1OfReal) aVal = aDimTolAttr->GetVal(); + Handle(TCollection_HAsciiString) aName = aDimTolAttr->GetName(); + Handle(TCollection_HAsciiString) aDescription = aDimTolAttr->GetDescription(); // common part of writing D> entities - StepRepr_CharacterizedDefinition CD; - Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect; - SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue); - Model->AddWithRefs(SA); - CD.SetValue(SA); - Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition; - PropD->Init(aName,Standard_True,aDescription,CD); - Model->AddWithRefs(PropD); - StepRepr_RepresentedDefinition RD; - RD.SetValue(PropD); - Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation; - Handle(StepRepr_HArray1OfRepresentationItem) HARI = - new StepRepr_HArray1OfRepresentationItem(1,1); - if(kind<20) - HARI->SetValue(1,EC); + StepRepr_CharacterizedDefinition aCD; + Handle(StepRepr_ShapeAspect) aSA = new StepRepr_ShapeAspect; + aSA->Init(aName, new TCollection_HAsciiString, aPDS, StepData_LTrue); + aModel->AddWithRefs(aSA); + aCD.SetValue(aSA); + Handle(StepRepr_PropertyDefinition) aPropD = new StepRepr_PropertyDefinition; + aPropD->Init(aName, Standard_True, aDescription, aCD); + aModel->AddWithRefs(aPropD); + StepRepr_RepresentedDefinition aRD; + aRD.SetValue(aPropD); + Handle(StepShape_ShapeRepresentation) aSR = new StepShape_ShapeRepresentation; + Handle(StepRepr_HArray1OfRepresentationItem) aHARI = + new StepRepr_HArray1OfRepresentationItem(1, 1); + if (aKind < 20) + aHARI->SetValue(1, anEC); else - HARI->SetValue(1,AF); - SR->Init(aName,HARI,RC); - Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation; - SDR->Init(RD,SR); - Model->AddWithRefs(SDR); + aHARI->SetValue(1, anAF); + aSR->Init(aName, aHARI, aRC); + Handle(StepShape_ShapeDefinitionRepresentation) aSDR = new StepShape_ShapeDefinitionRepresentation; + aSDR->Init(aRD, aSR); + aModel->AddWithRefs(aSDR); // define aUnit for creation LengthMeasureWithUnit (common for all) StepBasic_Unit aUnit; - aUnit = GetUnit(RC); + aUnit = GetUnit(aRC); // specific part of writing D> entities - if(kind<20) { //dimension - Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize; - DimSize->Init(SA,aDescription); - Model->AddWithRefs(DimSize); - if(aVal->Length()>1) { + if (aKind < 20) + { //dimension + Handle(StepShape_DimensionalSize) aDimSize = new StepShape_DimensionalSize; + aDimSize->Init(aSA, aDescription); + aModel->AddWithRefs(aDimSize); + if (aVal->Length() > 1) + { // create MeasureWithUnits - Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember; - MVM1->SetName("POSITIVE_LENGTH_MEASURE"); - MVM1->SetReal(aVal->Value(1)); - Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit; - MWU1->Init(MVM1,aUnit); - Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember; - MVM2->SetName("POSITIVE_LENGTH_MEASURE"); - MVM2->SetReal(aVal->Value(2)); - Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit; - MWU2->Init(MVM2,aUnit); - Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem; - RI1->Init(new TCollection_HAsciiString("lower limit")); - Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem; - RI2->Init(new TCollection_HAsciiString("upper limit")); - Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 = + Handle(StepBasic_MeasureValueMember) aMVM1 = new StepBasic_MeasureValueMember; + aMVM1->SetName("POSITIVE_LENGTH_MEASURE"); + aMVM1->SetReal(aVal->Value(1)); + Handle(StepBasic_MeasureWithUnit) aMWU1 = new StepBasic_MeasureWithUnit; + aMWU1->Init(aMVM1, aUnit); + Handle(StepBasic_MeasureValueMember) aMVM2 = new StepBasic_MeasureValueMember; + aMVM2->SetName("POSITIVE_LENGTH_MEASURE"); + aMVM2->SetReal(aVal->Value(2)); + Handle(StepBasic_MeasureWithUnit) aMWU2 = new StepBasic_MeasureWithUnit; + aMWU2->Init(aMVM2, aUnit); + Handle(StepRepr_RepresentationItem) aRI1 = new StepRepr_RepresentationItem; + aRI1->Init(new TCollection_HAsciiString("lower limit")); + Handle(StepRepr_RepresentationItem) aRI2 = new StepRepr_RepresentationItem; + aRI2->Init(new TCollection_HAsciiString("upper limit")); + Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aRILMU1 = new StepRepr_ReprItemAndLengthMeasureWithUnit; - RILMU1->Init(MWU1,RI1); - Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 = + aRILMU1->Init(aMWU1, aRI1); + Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aRILMU2 = new StepRepr_ReprItemAndLengthMeasureWithUnit; - RILMU2->Init(MWU2,RI2); - Model->AddWithRefs(RILMU1); - Model->AddWithRefs(RILMU2); - //Handle(StepRepr_CompoundItemDefinitionMember) CIDM = - // new StepRepr_CompoundItemDefinitionMember; - //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2); - //ArrTr->SetValue(1,RILMU1); - //ArrTr->SetValue(2,RILMU2); - //CIDM->SetArrTransient(ArrTr); - //CIDM->SetName("SET_REPRESENTATION_ITEM"); - //StepRepr_CompoundItemDefinition CID; - //CID.SetValue(CIDM); - Handle(StepRepr_HArray1OfRepresentationItem) HARIVR = - new StepRepr_HArray1OfRepresentationItem(1,2); - HARIVR->SetValue(1,RILMU1); - HARIVR->SetValue(2,RILMU2); - Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange; + aRILMU2->Init(aMWU2, aRI2); + aModel->AddWithRefs(aRILMU1); + aModel->AddWithRefs(aRILMU2); + Handle(StepRepr_HArray1OfRepresentationItem) aHARIVR = + new StepRepr_HArray1OfRepresentationItem(1, 2); + aHARIVR->SetValue(1, aRILMU1); + aHARIVR->SetValue(2, aRILMU2); + Handle(StepRepr_ValueRange) aVR = new StepRepr_ValueRange; //VR->Init(aName,CID); - VR->Init(aName,HARIVR); - Model->AddEntity(VR); - Handle(StepShape_ShapeDimensionRepresentation) SDimR = + aVR->Init(aName, aHARIVR); + aModel->AddEntity(aVR); + Handle(StepShape_ShapeDimensionRepresentation) aSDimR = new StepShape_ShapeDimensionRepresentation; - Handle(StepRepr_HArray1OfRepresentationItem) aHARI = - new StepRepr_HArray1OfRepresentationItem(1,1); - aHARI->SetValue(1,VR); - SDimR->Init(aName,aHARI,RC); - Model->AddWithRefs(SDimR); - Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR = + Handle(StepRepr_HArray1OfRepresentationItem) aHARI1 = + new StepRepr_HArray1OfRepresentationItem(1, 1); + aHARI1->SetValue(1, aVR); + aSDimR->Init(aName, aHARI1, aRC); + aModel->AddWithRefs(aSDimR); + Handle(StepShape_DimensionalCharacteristicRepresentation) aDimCharR = new StepShape_DimensionalCharacteristicRepresentation; - StepShape_DimensionalCharacteristic DimChar; - DimChar.SetValue(DimSize); - DimCharR->Init(DimChar,SDimR); - Model->AddEntity(DimCharR); + StepShape_DimensionalCharacteristic aDimChar; + aDimChar.SetValue(aDimSize); + aDimCharR->Init(aDimChar, aSDimR); + aModel->AddEntity(aDimCharR); } } - else if(kind<50) { //tolerance - if(kind<35) { // tolerance with datum system - TDF_LabelSequence DatumLabels; - DGTTool->GetDatumOfTolerLabels(DimTolL,DatumLabels); - Standard_Integer NbDR = DatumLabels.Length(); - Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR); - for(Standard_Integer j=1; j<=NbDR; j++) { - Handle(XCAFDoc_Datum) DatumAttr; - TDF_Label DatumL = DatumLabels.Value(j); - if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue; - Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName(); - Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription(); - Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification(); - TCollection_AsciiString stmp(aNameD->ToCString()); - stmp.AssignCat(aDescriptionD->ToCString()); - stmp.AssignCat(anIdentificationD->ToCString()); - if(DatumMap.IsBound(stmp)) { - Handle(StepDimTol_Datum) aDatum = - Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp)); - Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference; - DR->Init(j,aDatum); - Model->AddWithRefs(DR); - HADR->SetValue(j,DR); + else if (aKind < 50) + { //tolerance + if (aKind < 35) + { // tolerance with datum system + TDF_LabelSequence aDatumLabels; + XCAFDoc_DimTolTool::GetDatumOfTolerLabels(aDimTolL, aDatumLabels); + Standard_Integer aSetDatumInd = 1; + Handle(StepDimTol_HArray1OfDatumReference) aHADR = + new StepDimTol_HArray1OfDatumReference(1, aDatumLabels.Length()); + for (TDF_LabelSequence::Iterator aDatumIter(aDatumLabels); + aDatumIter.More(); aDatumIter.Next(), aSetDatumInd++) + { + Handle(XCAFDoc_Datum) aDatumAttr; + const TDF_Label& aDatumL = aDatumIter.Value(); + if (!aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr)) + continue; + Handle(TCollection_HAsciiString) aNameD = aDatumAttr->GetName(); + Handle(TCollection_HAsciiString) aDescriptionD = aDatumAttr->GetDescription(); + Handle(TCollection_HAsciiString) anIdentificationD = aDatumAttr->GetIdentification(); + TCollection_AsciiString aStmp(aNameD->ToCString()); + aStmp.AssignCat(aDescriptionD->ToCString()); + aStmp.AssignCat(anIdentificationD->ToCString()); + if (aDatumMap.IsBound(aStmp)) + { + Handle(StepDimTol_Datum) aDatum = + Handle(StepDimTol_Datum)::DownCast(aDatumMap.Find(aStmp)); + Handle(StepDimTol_DatumReference) aDR = new StepDimTol_DatumReference; + aDR->Init(aSetDatumInd, aDatum); + aModel->AddWithRefs(aDR); + aHADR->SetValue(aSetDatumInd, aDR); } } // create LengthMeasureWithUnit - Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember; - MVM->SetName("LENGTH_MEASURE"); - MVM->SetReal(aVal->Value(1)); - Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit; - LMWU->Init(MVM,aUnit); + Handle(StepBasic_MeasureValueMember) aMVM = new StepBasic_MeasureValueMember; + aMVM->SetName("LENGTH_MEASURE"); + aMVM->SetReal(aVal->Value(1)); + Handle(StepBasic_LengthMeasureWithUnit) aLMWU = new StepBasic_LengthMeasureWithUnit; + aLMWU->Init(aMVM, aUnit); // create tolerance by it's type - if(kind<24) { - Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR = + if (aKind < 24) + { + Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR = new StepDimTol_GeometricToleranceWithDatumReference; - GTWDR->SetDatumSystem(HADR); - Handle(StepDimTol_ModifiedGeometricTolerance) MGT = + aGTWDR->SetDatumSystem(aHADR); + Handle(StepDimTol_ModifiedGeometricTolerance) aMGT = new StepDimTol_ModifiedGeometricTolerance; - if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition); - else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition); - else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize); - Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex = + if (aKind == 21) + aMGT->SetModifier(StepDimTol_MaximumMaterialCondition); + else if (aKind == 22) + aMGT->SetModifier(StepDimTol_LeastMaterialCondition); + else if (aKind == 23) + aMGT->SetModifier(StepDimTol_RegardlessOfFeatureSize); + Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) aGTComplex = new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol; - GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT); - Model->AddWithRefs(GTComplex); + aGTComplex->Init(aName, aDescription, aLMWU, aSA, aGTWDR, aMGT); + aModel->AddWithRefs(aGTComplex); } - else if(kind==24) { + else if (aKind == 24) + { Handle(StepDimTol_AngularityTolerance) aToler = new StepDimTol_AngularityTolerance; - aToler->Init(aName,aDescription,LMWU,SA,HADR); - Model->AddWithRefs(aToler); + aToler->Init(aName, aDescription, aLMWU, aSA, aHADR); + aModel->AddWithRefs(aToler); } - else if(kind==25) { + else if (aKind == 25) + { Handle(StepDimTol_CircularRunoutTolerance) aToler = new StepDimTol_CircularRunoutTolerance; - aToler->Init(aName,aDescription,LMWU,SA,HADR); - Model->AddWithRefs(aToler); + aToler->Init(aName, aDescription, aLMWU, aSA, aHADR); + aModel->AddWithRefs(aToler); } - else if(kind==26) { + else if (aKind == 26) + { Handle(StepDimTol_CoaxialityTolerance) aToler = new StepDimTol_CoaxialityTolerance; - aToler->Init(aName,aDescription,LMWU,SA,HADR); - Model->AddWithRefs(aToler); + aToler->Init(aName, aDescription, aLMWU, aSA, aHADR); + aModel->AddWithRefs(aToler); } - else if(kind==27) { + else if (aKind == 27) + { Handle(StepDimTol_ConcentricityTolerance) aToler = new StepDimTol_ConcentricityTolerance; - aToler->Init(aName,aDescription,LMWU,SA,HADR); - Model->AddWithRefs(aToler); + aToler->Init(aName, aDescription, aLMWU, aSA, aHADR); + aModel->AddWithRefs(aToler); } - else if(kind==28) { + else if (aKind == 28) + { Handle(StepDimTol_ParallelismTolerance) aToler = new StepDimTol_ParallelismTolerance; - aToler->Init(aName,aDescription,LMWU,SA,HADR); - Model->AddWithRefs(aToler); + aToler->Init(aName, aDescription, aLMWU, aSA, aHADR); + aModel->AddWithRefs(aToler); } - else if(kind==29) { + else if (aKind == 29) + { Handle(StepDimTol_PerpendicularityTolerance) aToler = new StepDimTol_PerpendicularityTolerance; - aToler->Init(aName,aDescription,LMWU,SA,HADR); - Model->AddWithRefs(aToler); + aToler->Init(aName, aDescription, aLMWU, aSA, aHADR); + aModel->AddWithRefs(aToler); } - else if(kind==30) { + else if (aKind == 30) + { Handle(StepDimTol_SymmetryTolerance) aToler = new StepDimTol_SymmetryTolerance; - aToler->Init(aName,aDescription,LMWU,SA,HADR); - Model->AddWithRefs(aToler); + aToler->Init(aName, aDescription, aLMWU, aSA, aHADR); + aModel->AddWithRefs(aToler); } - else if(kind==31) { + else if (aKind == 31) + { Handle(StepDimTol_TotalRunoutTolerance) aToler = new StepDimTol_TotalRunoutTolerance; - aToler->Init(aName,aDescription,LMWU,SA,HADR); - Model->AddWithRefs(aToler); + aToler->Init(aName, aDescription, aLMWU, aSA, aHADR); + aModel->AddWithRefs(aToler); } } } @@ -3766,48 +3910,56 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSe } //======================================================================= -//function : WriteDGTsAP242 -//purpose : +//function : writeDGTsAP242 +//purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels ) +Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) { + (void)theLabels; // Get working data - const Handle(Interface_InterfaceModel) &aModel = WS->Model(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); - const Handle(Interface_HGraph) aHGraph = WS->HGraph(); - if(aHGraph.IsNull()) + const Handle(Interface_HGraph) aHGraph = theWS->HGraph(); + if (aHGraph.IsNull()) return Standard_False; Interface_Graph aGraph = aHGraph->Graph(); - Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool(labels(1)); - if(DGTTool.IsNull()) - return Standard_False; // Common entities for presentation - STEPConstruct_Styles aStyles (WS); + STEPConstruct_Styles aStyles(theWS); Handle(StepVisual_Colour) aCurvColor = aStyles.EncodeColor(Quantity_NOC_WHITE); Handle(StepRepr_RepresentationItem) anItem = NULL; myGDTPrsCurveStyle->SetValue(1, aStyles.MakeColorPSA(anItem, aCurvColor, aCurvColor, aCurvColor, 0.0)); - Interface_EntityIterator aModelIter = aModel->Entities(); - for (; aModelIter.More() && myGDTCommonPDS.IsNull(); aModelIter.Next()) + for (Interface_EntityIterator aModelIter = aModel->Entities(); + aModelIter.More() && myGDTCommonPDS.IsNull(); aModelIter.Next()) + { myGDTCommonPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aModelIter.Value()); + } - TDF_LabelSequence aDGTLabels; STEPConstruct_DataMapOfAsciiStringTransient aDatumMap; Handle(StepRepr_RepresentationContext) aRC; - //------------- // - // write Datums // - //--------------// - DGTTool->GetDatumLabels(aDGTLabels); + TDF_LabelSequence aDGTLabels; + // Iterate on requested shapes collect Tools + for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(aLabel); + TDF_LabelSequence aaDGTLS; + aDGTTool->GetDatumLabels(aDGTLabels); + aDGTLabels.Append(aaDGTLS); + } + // Find all shapes with datums TColStd_MapOfAsciiString aNameIdMap; - for(Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) { - TDF_Label aDatumL = aDGTLabels.Value(i); + for (TDF_LabelSequence::Iterator aDGTIter(aDGTLabels); + aDGTIter.More(); aDGTIter.Next()) + { + const TDF_Label& aDatumL = aDGTIter.Value(); TDF_LabelSequence aShapeL, aNullSeq; - DGTTool->GetRefShapeLabel(aDatumL, aShapeL, aNullSeq); + XCAFDoc_DimTolTool::GetRefShapeLabel(aDatumL, aShapeL, aNullSeq); Handle(XCAFDoc_Datum) aDatumAttr; aDatumL.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr); Handle(XCAFDimTolObjects_DatumObject) anObject = aDatumAttr->GetObject(); @@ -3817,17 +3969,24 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W continue; Handle(Standard_Transient) aWrittenDatum; Standard_Boolean isFirstDT = !aDatumMap.Find(aDatumName, aWrittenDatum); - Handle(StepDimTol_Datum) aDatum = WriteDatumAP242(WS, aShapeL, aDatumL, isFirstDT, - Handle(StepDimTol_Datum)::DownCast (aWrittenDatum)); + Handle(StepDimTol_Datum) aDatum = writeDatumAP242(theWS, aShapeL, aDatumL, isFirstDT, + Handle(StepDimTol_Datum)::DownCast(aWrittenDatum)); // Add created Datum into Map aDatumMap.Bind(aDatumName, aDatum); } - //----------------- // - // write Dimensions // - //------------------// + // write Dimensions aDGTLabels.Clear(); - DGTTool->GetDimensionLabels(aDGTLabels); + for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(aLabel); + TDF_LabelSequence aaDGTLS; + aDGTTool->GetDimensionLabels(aDGTLabels); + aDGTLabels.Append(aaDGTLS); + } + // Auxiliary entities for derived geometry Handle(StepRepr_ConstructiveGeometryRepresentation) aCGRepr = new StepRepr_ConstructiveGeometryRepresentation(); @@ -3836,11 +3995,13 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W NCollection_Vector aConnectionPnts; Handle(StepRepr_RepresentationContext) dummyRC; Handle(StepAP242_GeometricItemSpecificUsage) dummyGISU; - for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) { - TDF_Label aDimensionL = aDGTLabels.Value(i); + for (TDF_LabelSequence::Iterator aDGTIter(aDGTLabels); + aDGTIter.More(); aDGTIter.Next()) + { + const TDF_Label& aDimensionL = aDGTIter.Value(); TDF_LabelSequence aFirstShapeL, aSecondShapeL; Handle(XCAFDoc_Dimension) aDimAttr; - if (!aDimensionL.FindAttribute(XCAFDoc_Dimension::GetID(),aDimAttr)) + if (!aDimensionL.FindAttribute(XCAFDoc_Dimension::GetID(), aDimAttr)) continue; Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimAttr->GetObject(); if (anObject.IsNull()) @@ -3850,29 +4011,33 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W Handle(StepRepr_ShapeAspect) aSA = new StepRepr_ShapeAspect(); aSA->Init(new TCollection_HAsciiString(), new TCollection_HAsciiString(), myGDTCommonPDS, StepData_LTrue); aModel->AddWithRefs(aSA); - WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->HasPlane(), - Standard_False, anObject->GetPlane(), anObject->GetPointTextAttach(), aSA); + writePresentation(theWS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->HasPlane(), + Standard_False, anObject->GetPlane(), anObject->GetPointTextAttach(), aSA); } - if (!DGTTool->GetRefShapeLabel(aDimensionL, aFirstShapeL, aSecondShapeL)) + if (!XCAFDoc_DimTolTool::GetRefShapeLabel(aDimensionL, aFirstShapeL, aSecondShapeL)) continue; // Write links with shapes Handle(StepRepr_ShapeAspect) aFirstSA, aSecondSA; - if (aFirstShapeL.Length() == 1) { + if (aFirstShapeL.Length() == 1) + { TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(1)); - aFirstSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU); + aFirstSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); if (aRC.IsNull() && !dummyRC.IsNull()) aRC = dummyRC; } - else if (aFirstShapeL.Length() > 1) { + else if (aFirstShapeL.Length() > 1) + { Handle(StepRepr_CompositeShapeAspect) aCSA; - for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) { + for (Standard_Integer shIt = 1; shIt <= aFirstShapeL.Length(); shIt++) + { TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aFirstShapeL.Value(shIt)); - Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU); + Handle(StepRepr_ShapeAspect) aSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); if (aSA.IsNull()) continue; - if (aCSA.IsNull()) { + if (aCSA.IsNull()) + { aCSA = new StepRepr_CompositeShapeAspect(); aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional()); aModel->AddWithRefs(aCSA); @@ -3885,23 +4050,27 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W } aFirstSA = aCSA; } - if (aSecondShapeL.Length() == 1) { + if (aSecondShapeL.Length() == 1) + { TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(1)); - aSecondSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU); + aSecondSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); if (aRC.IsNull() && !dummyRC.IsNull()) aRC = dummyRC; } - else if (aSecondShapeL.Length() > 1) { + else if (aSecondShapeL.Length() > 1) + { Handle(StepRepr_CompositeShapeAspect) aCSA; - for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++) { + for (Standard_Integer shIt = 1; shIt <= aSecondShapeL.Length(); shIt++) + { TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aSecondShapeL.Value(shIt)); - Handle(StepRepr_ShapeAspect) aSA = WriteShapeAspect(WS, aDimensionL, aShape, dummyRC, dummyGISU); + Handle(StepRepr_ShapeAspect) aSA = writeShapeAspect(theWS, aDimensionL, aShape, dummyRC, dummyGISU); if (aCSA.IsNull() && !aSA.IsNull()) { aCSA = new StepRepr_CompositeShapeAspect(); } aCSA->Init(aSA->Name(), aSA->Description(), aSA->OfShape(), aSA->ProductDefinitional()); - if (!aSA.IsNull()) { + if (!aSA.IsNull()) + { Handle(StepRepr_ShapeAspectRelationship) aSAR = new StepRepr_ShapeAspectRelationship(); aSAR->Init(new TCollection_HAsciiString(), Standard_False, new TCollection_HAsciiString(), aCSA, aSA); aModel->AddWithRefs(aSAR); @@ -3914,32 +4083,36 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W if (anObject->GetType() == XCAFDimTolObjects_DimensionType_DimensionPresentation) { - WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->HasPlane(), - Standard_False, anObject->GetPlane(), anObject->GetPointTextAttach(), aFirstSA); + writePresentation(theWS, anObject->GetPresentation(), anObject->GetPresentationName(), anObject->HasPlane(), + Standard_False, anObject->GetPlane(), anObject->GetPointTextAttach(), aFirstSA); continue; } // Write dimensions StepShape_DimensionalCharacteristic aDimension; if (anObject->HasPoint() || anObject->HasPoint2()) - WriteDerivedGeometry(WS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionPnts); + WriteDerivedGeometry(theWS, anObject, aCGRepr, aFirstSA, aSecondSA, aConnectionPnts); XCAFDimTolObjects_DimensionType aDimType = anObject->GetType(); - if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) { + if (STEPCAFControl_GDTProperty::IsDimensionalLocation(aDimType)) + { // Dimensional_Location Handle(StepShape_DimensionalLocation) aDim = new StepShape_DimensionalLocation(); aDim->Init(STEPCAFControl_GDTProperty::GetDimTypeName(aDimType), Standard_False, NULL, aFirstSA, aSecondSA); aDimension.SetValue(aDim); } - else if (aDimType == XCAFDimTolObjects_DimensionType_Location_Angular) { + else if (aDimType == XCAFDimTolObjects_DimensionType_Location_Angular) + { // Angular_Location Handle(StepShape_AngularLocation) aDim = new StepShape_AngularLocation(); StepShape_AngleRelator aRelator = StepShape_Equal; - if (anObject->HasQualifier()) { + if (anObject->HasQualifier()) + { XCAFDimTolObjects_AngularQualifier aQualifier = anObject->GetAngularQualifier(); - switch (aQualifier) { - case XCAFDimTolObjects_AngularQualifier_Small : aRelator = StepShape_Small; + switch (aQualifier) + { + case XCAFDimTolObjects_AngularQualifier_Small: aRelator = StepShape_Small; break; - case XCAFDimTolObjects_AngularQualifier_Large : aRelator = StepShape_Large; + case XCAFDimTolObjects_AngularQualifier_Large: aRelator = StepShape_Large; break; default: aRelator = StepShape_Equal; } @@ -3947,26 +4120,31 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aRelator); aDimension.SetValue(aDim); } - else if (aDimType == XCAFDimTolObjects_DimensionType_Location_WithPath) { + else if (aDimType == XCAFDimTolObjects_DimensionType_Location_WithPath) + { // Dimensional_Location_With_Path Handle(StepShape_DimensionalLocationWithPath) aDim = new StepShape_DimensionalLocationWithPath(); - Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU); + Handle(StepRepr_ShapeAspect) aPathSA = writeShapeAspect(theWS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU); aDim->Init(new TCollection_HAsciiString(), Standard_False, NULL, aFirstSA, aSecondSA, aPathSA); aDimension.SetValue(aDim); } - else if (STEPCAFControl_GDTProperty::IsDimensionalSize(aDimType)) { + else if (STEPCAFControl_GDTProperty::IsDimensionalSize(aDimType)) + { // Dimensional_Size Handle(StepShape_DimensionalSize) aDim = new StepShape_DimensionalSize(); aDim->Init(aFirstSA, STEPCAFControl_GDTProperty::GetDimTypeName(aDimType)); aDimension.SetValue(aDim); } - else if (aDimType == XCAFDimTolObjects_DimensionType_Size_Angular) { + else if (aDimType == XCAFDimTolObjects_DimensionType_Size_Angular) + { // Angular_Size Handle(StepShape_AngularSize) aDim = new StepShape_AngularSize(); StepShape_AngleRelator aRelator = StepShape_Equal; - if (anObject->HasQualifier()) { + if (anObject->HasQualifier()) + { XCAFDimTolObjects_AngularQualifier aQualifier = anObject->GetAngularQualifier(); - switch (aQualifier) { + switch (aQualifier) + { case XCAFDimTolObjects_AngularQualifier_Small: aRelator = StepShape_Small; break; case XCAFDimTolObjects_AngularQualifier_Large: aRelator = StepShape_Large; @@ -3977,22 +4155,24 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W aDim->Init(aFirstSA, new TCollection_HAsciiString(), aRelator); aDimension.SetValue(aDim); } - else if (aDimType == XCAFDimTolObjects_DimensionType_Size_WithPath) { + else if (aDimType == XCAFDimTolObjects_DimensionType_Size_WithPath) + { // Dimensional_Size_With_Path Handle(StepShape_DimensionalSizeWithPath) aDim = new StepShape_DimensionalSizeWithPath(); - Handle(StepRepr_ShapeAspect) aPathSA = WriteShapeAspect(WS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU); + Handle(StepRepr_ShapeAspect) aPathSA = writeShapeAspect(theWS, aDimensionL, anObject->GetPath(), dummyRC, dummyGISU); aDim->Init(aFirstSA, new TCollection_HAsciiString(), aPathSA); aDimension.SetValue(aDim); } // Write values - WriteDimValues(WS, anObject, aRC, aDimension); + WriteDimValues(theWS, anObject, aRC, aDimension); //Annotation plane and Presentation - WritePresentation(WS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(), - anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value()); + writePresentation(theWS, anObject->GetPresentation(), anObject->GetPresentationName(), Standard_True, anObject->HasPlane(), + anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value()); } // Write Derived geometry - if (aConnectionPnts.Length() > 0) { + if (aConnectionPnts.Length() > 0) + { Handle(StepRepr_HArray1OfRepresentationItem) anItems = new StepRepr_HArray1OfRepresentationItem(1, aConnectionPnts.Length()); for (Standard_Integer i = 0; i < aConnectionPnts.Length(); i++) anItems->SetValue(i + 1, aConnectionPnts(i)); @@ -4001,22 +4181,30 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W aModel->AddWithRefs(aCGReprRel); } - //----------------------------// - // write Geometric Tolerances // - //----------------------------// + // write Geometric Tolerances aDGTLabels.Clear(); - DGTTool->GetGeomToleranceLabels(aDGTLabels); - for (Standard_Integer i = 1; i <= aDGTLabels.Length(); i++) { - TDF_Label aGeomTolL = aDGTLabels.Value(i); + for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(aLabel); + TDF_LabelSequence aaDGTLS; + aDGTTool->GetGeomToleranceLabels(aDGTLabels); + aDGTLabels.Append(aaDGTLS); + } + for (TDF_LabelSequence::Iterator aDGTIter(aDGTLabels); + aDGTIter.More(); aDGTIter.Next()) + { + const TDF_Label aGeomTolL = aDGTIter.Value(); TDF_LabelSequence aFirstShapeL, aNullSeqL; - if (!DGTTool->GetRefShapeLabel(aGeomTolL, aFirstShapeL, aNullSeqL)) + if (!XCAFDoc_DimTolTool::GetRefShapeLabel(aGeomTolL, aFirstShapeL, aNullSeqL)) continue; TDF_LabelSequence aDatumSeq; - DGTTool->GetDatumWithObjectOfTolerLabels(aGeomTolL, aDatumSeq); + XCAFDoc_DimTolTool::GetDatumWithObjectOfTolerLabels(aGeomTolL, aDatumSeq); Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem; if (aDatumSeq.Length() > 0) - aDatumSystem = WriteDatumSystem(WS, aGeomTolL, aDatumSeq, aDatumMap, aRC); - WriteGeomTolerance(WS, aFirstShapeL, aGeomTolL, aDatumSystem, aRC); + aDatumSystem = WriteDatumSystem(theWS, aGeomTolL, aDatumSeq, aDatumMap, aRC); + writeGeomTolerance(theWS, aFirstShapeL, aGeomTolL, aDatumSystem, aRC); } // Write Draughting model for Annotation Planes @@ -4025,7 +4213,8 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W Handle(StepRepr_HArray1OfRepresentationItem) aItems = new StepRepr_HArray1OfRepresentationItem(1, myGDTAnnotations.Length()); - for (Standard_Integer i = 1; i <= aItems->Length(); i++) { + for (Standard_Integer i = 1; i <= aItems->Length(); i++) + { aItems->SetValue(i, myGDTAnnotations.Value(i - 1)); } myGDTPresentationDM->Init(new TCollection_HAsciiString(), aItems, aRC); @@ -4036,335 +4225,202 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W //======================================================================= //function : FindPDSforRI -//purpose : auxiliary: +//purpose : auxiliary: //======================================================================= -static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph, - const Handle(Standard_Transient) &ent, - Handle(StepRepr_ProductDefinitionShape) &PDS, - Handle(StepRepr_RepresentationContext) &RC) +static Standard_Boolean FindPDSforRI(const Interface_Graph& theGraph, + const Handle(Standard_Transient)& theEnt, + Handle(StepRepr_ProductDefinitionShape)& thePDS, + Handle(StepRepr_RepresentationContext)& theRC) { - if(ent.IsNull() || !ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) + if (theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) return Standard_False; - Interface_EntityIterator subs = aGraph.Sharings(ent); - for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) { - Handle(StepShape_ShapeRepresentation) SR = - Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value()); - if(SR.IsNull()) continue; - RC = SR->ContextOfItems(); - Interface_EntityIterator subs1 = aGraph.Sharings(SR); - for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) { - Handle(StepShape_ShapeDefinitionRepresentation) SDR = - Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value()); - if(SDR.IsNull()) continue; - Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition(); - if(PropD.IsNull()) continue; - PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD); + for (Interface_EntityIterator aSharingIter = theGraph.Sharings(theEnt); + aSharingIter.More() && thePDS.IsNull(); aSharingIter.Next()) + { + Handle(StepShape_ShapeRepresentation) aSR = + Handle(StepShape_ShapeRepresentation)::DownCast(aSharingIter.Value()); + if (aSR.IsNull()) + continue; + theRC = aSR->ContextOfItems(); + for (Interface_EntityIterator aSubs1 = theGraph.Sharings(aSR); + aSubs1.More() && thePDS.IsNull(); aSubs1.Next()) + { + Handle(StepShape_ShapeDefinitionRepresentation) aSDR = + Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSubs1.Value()); + if (aSDR.IsNull()) + continue; + Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition(); + if (aPropD.IsNull()) + continue; + thePDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD); } } return Standard_True; } - //======================================================================= -//function : WriteMaterials -//purpose : +//function : writeMaterials +//purpose : //======================================================================= - -Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS, - const TDF_LabelSequence &labels ) const +Standard_Boolean STEPCAFControl_Writer::writeMaterials(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const { - - if ( labels.Length() <=0 ) return Standard_False; + + if (theLabels.IsEmpty()) + return Standard_False; // get working data - const Handle(Interface_InterfaceModel) &Model = WS->Model(); - const Handle(XSControl_TransferWriter) &TW = WS->TransferWriter(); - const Handle(Transfer_FinderProcess) &FP = TW->FinderProcess(); + const Handle(Interface_InterfaceModel)& aModel = theWS->Model(); + const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter(); + const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess(); - const Handle(Interface_HGraph) aHGraph = WS->HGraph(); - if(aHGraph.IsNull()) + const Handle(Interface_HGraph) aHGraph = theWS->HGraph(); + if (aHGraph.IsNull()) return Standard_False; - Interface_Graph aGraph = WS->HGraph()->Graph(); - Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) ); - if(ShTool.IsNull() ) return Standard_False; - Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) ); - if(MatTool.IsNull() ) return Standard_False; + Interface_Graph aGraph = theWS->HGraph()->Graph(); - STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI; - TDF_LabelSequence TopLabels; - ShTool->GetShapes(TopLabels); - for(Standard_Integer i=1; i<=TopLabels.Length(); i++) { - TDF_Label ShL = TopLabels.Value(i); - Handle(TDataStd_TreeNode) Node; - if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) { - // find PDS for current shape - TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL); - TopLoc_Location Loc; - TColStd_SequenceOfTransient seqRI; - FindEntities( FP, aShape, Loc, seqRI ); - if(seqRI.Length()<=0) continue; - Handle(StepRepr_ProductDefinitionShape) PDS; - Handle(StepRepr_RepresentationContext) RC; - Handle(Standard_Transient) ent = seqRI.Value(1); - FindPDSforRI(aGraph,ent,PDS,RC); - if(PDS.IsNull()) continue; - Handle(StepBasic_ProductDefinition) aProdDef = - PDS->Definition().ProductDefinition(); - if(aProdDef.IsNull()) + STEPConstruct_DataMapOfAsciiStringTransient aMapDRI, aMapMRI; + TDF_LabelSequence aTopLabels; + // Iterate on requested shapes collect Tools + for (TDF_LabelMap::Iterator aLabelIter(myRootLabels); + aLabelIter.More(); aLabelIter.Next()) + { + const TDF_Label& aLabel = aLabelIter.Value(); + Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool(aLabel); + TDF_LabelSequence aTopInterLabels; + aShTool->GetShapes(aTopInterLabels); + aTopLabels.Append(aTopInterLabels); + } + for (TDF_LabelSequence::Iterator aTopLIter(aTopLabels); + aTopLIter.More(); aTopLIter.Next()) + { + const TDF_Label& aShL = aTopLIter.Value(); + Handle(TDataStd_TreeNode) aNode; + if (!aShL.FindAttribute(XCAFDoc::MaterialRefGUID(), aNode) || !aNode->HasFather()) + { + continue; + } + // find PDS for current shape + TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aShL); + TopLoc_Location aLocation; + TColStd_SequenceOfTransient aSeqRI; + FindEntities(aFP, aShape, aLocation, aSeqRI); + if (aSeqRI.Length() <= 0) continue; + Handle(StepRepr_ProductDefinitionShape) aPDS; + Handle(StepRepr_RepresentationContext) aRC; + Handle(Standard_Transient) anEnt = aSeqRI.Value(1); + FindPDSforRI(aGraph, anEnt, aPDS, aRC); + if (aPDS.IsNull()) + continue; + Handle(StepBasic_ProductDefinition) aProdDef = + aPDS->Definition().ProductDefinition(); + if (aProdDef.IsNull()) + continue; + // write material entities + TDF_Label aMatL = aNode->Father()->Label(); + Handle(TCollection_HAsciiString) aName; + Handle(TCollection_HAsciiString) aDescription; + Standard_Real aDensity; + Handle(TCollection_HAsciiString) aDensName; + Handle(TCollection_HAsciiString) aDensValType; + Handle(StepRepr_Representation) aRepDRI; + Handle(StepRepr_Representation) aRepMRI; + if (XCAFDoc_MaterialTool::GetMaterial(aMatL, aName, aDescription, aDensity, aDensName, aDensValType)) + { + if (aName->Length() == 0) continue; - // write material entities - TDF_Label MatL = Node->Father()->Label(); - Handle(TCollection_HAsciiString) aName; - Handle(TCollection_HAsciiString) aDescription; - Standard_Real aDensity; - Handle(TCollection_HAsciiString) aDensName; - Handle(TCollection_HAsciiString) aDensValType; - Handle(StepRepr_Representation) RepDRI; - Handle(StepRepr_Representation) RepMRI; - if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) { - if(aName->Length()==0) continue; - TCollection_AsciiString aKey(aName->ToCString()); - if(MapDRI.IsBound(aKey)) { - RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey)); - if(MapMRI.IsBound(aKey)) { - RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey)); - } - } - else { - // write DRI - Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem; - DRI->Init(aName,aDescription); - Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1); - HARI->SetValue(1,DRI); - RepDRI = new StepRepr_Representation(); - RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC); - Model->AddWithRefs(RepDRI); - // write MRI - if( aDensity > 0 ) { - // mass - Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit; - SMU->SetName(StepBasic_sunGram); - Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement; - DUE1->Init(SMU,3.0); - // length - Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit; - SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre); - Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement; - DUE2->Init(SLU,2.0); - // other - Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2); - HADUE->SetValue(1,DUE1); - HADUE->SetValue(2,DUE2); - Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit; - DU->Init(HADUE); - Model->AddWithRefs(DU); - StepBasic_Unit aUnit; - aUnit.SetValue(DU); - Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember; - MVM->SetName(aDensValType->ToCString()); - MVM->SetReal(aDensity); - Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem; - MRI->Init(aDensName,MVM,aUnit); - HARI = new StepRepr_HArray1OfRepresentationItem(1,1); - HARI->SetValue(1,MRI); - RepMRI = new StepRepr_Representation(); - RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC); - Model->AddWithRefs(RepMRI); - } - //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI); - MapDRI.Bind(aKey,RepDRI); - if ( !RepMRI.IsNull() ) MapMRI.Bind (aKey, RepMRI); + TCollection_AsciiString aKey(aName->ToCString()); + if (aMapDRI.IsBound(aKey)) + { + aRepDRI = Handle(StepRepr_Representation)::DownCast(aMapDRI.Find(aKey)); + if (aMapMRI.IsBound(aKey)) + { + aRepMRI = Handle(StepRepr_Representation)::DownCast(aMapMRI.Find(aKey)); } } - - if( !RepDRI.IsNull() ) + else { - StepRepr_CharacterizedDefinition CD1; - CD1.SetValue(aProdDef); - Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition; - PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True, - new TCollection_HAsciiString("material name"),CD1); - Model->AddWithRefs(PropD1); - StepRepr_RepresentedDefinition RD1; - RD1.SetValue(PropD1); - Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 = - new StepRepr_PropertyDefinitionRepresentation; - PDR1->Init(RD1,RepDRI); - Model->AddWithRefs(PDR1); - - if( !RepMRI.IsNull() ) + // write DRI + Handle(StepRepr_DescriptiveRepresentationItem) aDRI = new StepRepr_DescriptiveRepresentationItem; + aDRI->Init(aName, aDescription); + Handle(StepRepr_HArray1OfRepresentationItem) aHARI = new StepRepr_HArray1OfRepresentationItem(1, 1); + aHARI->SetValue(1, aDRI); + aRepDRI = new StepRepr_Representation(); + aRepDRI->Init(new TCollection_HAsciiString("material name"), aHARI, aRC); + aModel->AddWithRefs(aRepDRI); + // write MRI + if (aDensity > 0) { - StepRepr_CharacterizedDefinition CD2; - CD2.SetValue (aProdDef); - Handle (StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition; - PropD2->Init (new TCollection_HAsciiString ("material property"), Standard_True, - new TCollection_HAsciiString ("density"), CD2); - Model->AddWithRefs (PropD2); - StepRepr_RepresentedDefinition RD2; - RD2.SetValue (PropD2); - Handle (StepRepr_PropertyDefinitionRepresentation) PDR2 = - new StepRepr_PropertyDefinitionRepresentation; - PDR2->Init (RD2, RepMRI); - Model->AddWithRefs (PDR2); + // mass + Handle(StepBasic_SiUnitAndMassUnit) aSMU = new StepBasic_SiUnitAndMassUnit; + aSMU->SetName(StepBasic_sunGram); + Handle(StepBasic_DerivedUnitElement) aDUE1 = new StepBasic_DerivedUnitElement; + aDUE1->Init(aSMU, 3.0); + // length + Handle(StepBasic_SiUnitAndLengthUnit) aSLU = new StepBasic_SiUnitAndLengthUnit; + aSLU->Init(Standard_True, StepBasic_spCenti, StepBasic_sunMetre); + Handle(StepBasic_DerivedUnitElement) aDUE2 = new StepBasic_DerivedUnitElement; + aDUE2->Init(aSLU, 2.0); + // other + Handle(StepBasic_HArray1OfDerivedUnitElement) aHADUE = new StepBasic_HArray1OfDerivedUnitElement(1, 2); + aHADUE->SetValue(1, aDUE1); + aHADUE->SetValue(2, aDUE2); + Handle(StepBasic_DerivedUnit) aDU = new StepBasic_DerivedUnit; + aDU->Init(aHADUE); + aModel->AddWithRefs(aDU); + StepBasic_Unit aUnit; + aUnit.SetValue(aDU); + Handle(StepBasic_MeasureValueMember) aMVM = new StepBasic_MeasureValueMember; + aMVM->SetName(aDensValType->ToCString()); + aMVM->SetReal(aDensity); + Handle(StepRepr_MeasureRepresentationItem) aMRI = new StepRepr_MeasureRepresentationItem; + aMRI->Init(aDensName, aMVM, aUnit); + aHARI = new StepRepr_HArray1OfRepresentationItem(1, 1); + aHARI->SetValue(1, aMRI); + aRepMRI = new StepRepr_Representation(); + aRepMRI->Init(new TCollection_HAsciiString("density"), aHARI, aRC); + aModel->AddWithRefs(aRepMRI); } + //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI); + aMapDRI.Bind(aKey, aRepDRI); + if (!aRepMRI.IsNull()) + aMapMRI.Bind(aKey, aRepMRI); + } + } + + if (!aRepDRI.IsNull()) + { + StepRepr_CharacterizedDefinition aCD1; + aCD1.SetValue(aProdDef); + Handle(StepRepr_PropertyDefinition) aPropD1 = new StepRepr_PropertyDefinition; + aPropD1->Init(new TCollection_HAsciiString("material property"), Standard_True, + new TCollection_HAsciiString("material name"), aCD1); + aModel->AddWithRefs(aPropD1); + StepRepr_RepresentedDefinition aRD1; + aRD1.SetValue(aPropD1); + Handle(StepRepr_PropertyDefinitionRepresentation) aPDR1 = + new StepRepr_PropertyDefinitionRepresentation; + aPDR1->Init(aRD1, aRepDRI); + aModel->AddWithRefs(aPDR1); + + if (!aRepMRI.IsNull()) + { + StepRepr_CharacterizedDefinition aCD2; + aCD2.SetValue(aProdDef); + Handle(StepRepr_PropertyDefinition) aPropD2 = new StepRepr_PropertyDefinition; + aPropD2->Init(new TCollection_HAsciiString("material property"), Standard_True, + new TCollection_HAsciiString("density"), aCD2); + aModel->AddWithRefs(aPropD2); + StepRepr_RepresentedDefinition aRD2; + aRD2.SetValue(aPropD2); + Handle(StepRepr_PropertyDefinitionRepresentation) aPDR2 = + new StepRepr_PropertyDefinitionRepresentation; + aPDR2->Init(aRD2, aRepMRI); + aModel->AddWithRefs(aPDR2); } } } return Standard_True; } - - -//======================================================================= -//function : SetColorMode -//purpose : -//======================================================================= - -void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode) -{ - myColorMode = colormode; -} - - -//======================================================================= -//function : GetColorMode -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::GetColorMode () const -{ - return myColorMode; -} - - -//======================================================================= -//function : SetNameMode -//purpose : -//======================================================================= - -void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode) -{ - myNameMode = namemode; -} - - -//======================================================================= -//function : GetNameMode -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::GetNameMode () const -{ - return myNameMode; -} - - -//======================================================================= -//function : SetLayerMode -//purpose : -//======================================================================= - -void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode) -{ - myLayerMode = layermode; -} - - -//======================================================================= -//function : GetLayerMode -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const -{ - return myLayerMode; -} - - -//======================================================================= -//function : SetPropsMode -//purpose : -//======================================================================= - -void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode) -{ - myPropsMode = propsmode; -} - - -//======================================================================= -//function : GetPropsMode -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const -{ - return myPropsMode; -} - - -//======================================================================= -//function : SetSHUOMode -//purpose : -//======================================================================= - -void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode) -{ - mySHUOMode = mode; -} - - -//======================================================================= -//function : GetSHUOMode -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const -{ - return mySHUOMode; -} - - -//======================================================================= -//function : SetDimTolMode -//purpose : -//======================================================================= - -void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode) -{ - myGDTMode = dimtolmode; -} - - -//======================================================================= -//function : GetDimTolMode -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const -{ - return myGDTMode; -} - - -//======================================================================= -//function : SetMaterialMode -//purpose : -//======================================================================= - -void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode) -{ - myMatMode = matmode; -} - - -//======================================================================= -//function : GetMaterialMode -//purpose : -//======================================================================= - -Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const -{ - return myMatMode; -} diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.hxx b/src/STEPCAFControl/STEPCAFControl_Writer.hxx index ca7f4b5340..c38d32a2f4 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.hxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.hxx @@ -31,6 +31,7 @@ #include #include #include +#include #include class XSControl_WorkSession; @@ -44,219 +45,234 @@ class TopoDS_Shape; //! colors and part names //! //! Also supports multifile writing -class STEPCAFControl_Writer +class STEPCAFControl_Writer { + DEFINE_STANDARD_ALLOC public: - DEFINE_STANDARD_ALLOC - - //! Creates a writer with an empty //! STEP model and sets ColorMode, LayerMode, NameMode and //! PropsMode to Standard_True. Standard_EXPORT STEPCAFControl_Writer(); - + //! Creates a reader tool and attaches it to an already existing Session //! Clears the session if it was not yet set for STEP //! Clears the internal data structures - Standard_EXPORT STEPCAFControl_Writer(const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True); - + Standard_EXPORT STEPCAFControl_Writer(const Handle(XSControl_WorkSession)& theWS, + const Standard_Boolean theScratch = Standard_True); + //! Clears the internal data structures and attaches to a new session //! Clears the session if it was not yet set for STEP - Standard_EXPORT void Init (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True); - + Standard_EXPORT void Init(const Handle(XSControl_WorkSession)& theWS, + const Standard_Boolean theScratch = Standard_True); + //! Writes all the produced models into file //! In case of multimodel with extern references, //! filename will be a name of root file, all other files //! have names of corresponding parts //! Provided for use like single-file writer - Standard_EXPORT IFSelect_ReturnStatus Write (const Standard_CString theFileName); + Standard_EXPORT IFSelect_ReturnStatus Write(const Standard_CString theFileName); //! Writes all the produced models into the stream. //! Provided for use like single-file writer - Standard_EXPORT IFSelect_ReturnStatus WriteStream (std::ostream& theStream); - + Standard_EXPORT IFSelect_ReturnStatus WriteStream(std::ostream& theStream); + //! Transfers a document (or single label) to a STEP model //! The mode of translation of shape is AsIs //! If multi is not null pointer, it switches to multifile //! mode (with external refs), and string pointed by //! gives prefix for names of extern files (can be empty string) //! Returns True if translation is OK - Standard_EXPORT Standard_Boolean Transfer (const Handle(TDocStd_Document)& doc, - const STEPControl_StepModelType mode = STEPControl_AsIs, - const Standard_CString multi = 0, - const Message_ProgressRange& theProgress = Message_ProgressRange()); - + Standard_EXPORT Standard_Boolean Transfer(const Handle(TDocStd_Document)& theDoc, + const STEPControl_StepModelType theMode = STEPControl_AsIs, + const Standard_CString theIsMulti = 0, + const Message_ProgressRange& theProgress = Message_ProgressRange()); + //! Method to transfer part of the document specified by label - Standard_EXPORT Standard_Boolean Transfer (const TDF_Label& L, - const STEPControl_StepModelType mode = STEPControl_AsIs, - const Standard_CString multi = 0, - const Message_ProgressRange& theProgress = Message_ProgressRange()); + Standard_EXPORT Standard_Boolean Transfer(const TDF_Label& theLabel, + const STEPControl_StepModelType theMode = STEPControl_AsIs, + const Standard_CString theIsMulti = 0, + const Message_ProgressRange& theProgress = Message_ProgressRange()); //! Mehod to writing sequence of root assemblies or part of the file specified by use by one label - Standard_EXPORT Standard_Boolean Transfer (const TDF_LabelSequence& L, - const STEPControl_StepModelType mode = STEPControl_AsIs, - const Standard_CString multi = 0, - const Message_ProgressRange& theProgress = Message_ProgressRange()); - - Standard_EXPORT Standard_Boolean Perform (const Handle(TDocStd_Document)& doc, - const TCollection_AsciiString& filename, + Standard_EXPORT Standard_Boolean Transfer(const TDF_LabelSequence& theLabelSeq, + const STEPControl_StepModelType theMode = STEPControl_AsIs, + const Standard_CString theIsMulti = 0, const Message_ProgressRange& theProgress = Message_ProgressRange()); - + + Standard_EXPORT Standard_Boolean Perform(const Handle(TDocStd_Document)& theDoc, + const TCollection_AsciiString& theFileName, + const Message_ProgressRange& theProgress = Message_ProgressRange()); + //! Transfers a document and writes it to a STEP file //! Returns True if translation is OK - Standard_EXPORT Standard_Boolean Perform (const Handle(TDocStd_Document)& doc, - const Standard_CString filename, - const Message_ProgressRange& theProgress = Message_ProgressRange()); - + Standard_EXPORT Standard_Boolean Perform(const Handle(TDocStd_Document)& theDoc, + const Standard_CString theFileName, + const Message_ProgressRange& theProgress = Message_ProgressRange()); + //! Returns data on external files //! Returns Null handle if no external files are read - Standard_EXPORT const NCollection_DataMap& ExternFiles() const; - + const NCollection_DataMap& ExternFiles() const { return myFiles; }; + //! Returns data on external file by its original label //! Returns False if no external file with given name is read - Standard_EXPORT Standard_Boolean ExternFile (const TDF_Label& L, Handle(STEPCAFControl_ExternFile)& ef) const; - + Standard_EXPORT Standard_Boolean ExternFile(const TDF_Label& theLabel, + Handle(STEPCAFControl_ExternFile)& theExtFile) const; + //! Returns data on external file by its name //! Returns False if no external file with given name is read - Standard_EXPORT Standard_Boolean ExternFile (const Standard_CString name, Handle(STEPCAFControl_ExternFile)& ef) const; - + Standard_EXPORT Standard_Boolean ExternFile(const Standard_CString theName, + Handle(STEPCAFControl_ExternFile)& theExtFile) const; + //! Returns basic reader for root file - Standard_EXPORT STEPControl_Writer& ChangeWriter(); - + STEPControl_Writer& ChangeWriter() { return myWriter; } + //! Returns basic reader as const - Standard_EXPORT const STEPControl_Writer& Writer() const; - + const STEPControl_Writer& Writer() const { return myWriter; } + //! Set ColorMode for indicate write Colors or not. - Standard_EXPORT void SetColorMode (const Standard_Boolean colormode); - - Standard_EXPORT Standard_Boolean GetColorMode() const; - + void SetColorMode(const Standard_Boolean theColorMode) { myColorMode = theColorMode; } + + Standard_Boolean GetColorMode() const { return myColorMode; } + //! Set NameMode for indicate write Name or not. - Standard_EXPORT void SetNameMode (const Standard_Boolean namemode); - - Standard_EXPORT Standard_Boolean GetNameMode() const; - + void SetNameMode(const Standard_Boolean theNameMode) { myNameMode = theNameMode; } + + Standard_Boolean GetNameMode() const { return myNameMode; } + //! Set LayerMode for indicate write Layers or not. - Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode); - - Standard_EXPORT Standard_Boolean GetLayerMode() const; - + void SetLayerMode(const Standard_Boolean theLayerMode) { myLayerMode = theLayerMode; } + + Standard_Boolean GetLayerMode() const { return myLayerMode; } + //! PropsMode for indicate write Validation properties or not. - Standard_EXPORT void SetPropsMode (const Standard_Boolean propsmode); - - Standard_EXPORT Standard_Boolean GetPropsMode() const; - + void SetPropsMode(const Standard_Boolean thePropsMode) { myPropsMode = thePropsMode; } + + Standard_Boolean GetPropsMode() const { return myPropsMode; } + //! Set SHUO mode for indicate write SHUO or not. - Standard_EXPORT void SetSHUOMode (const Standard_Boolean shuomode); - - Standard_EXPORT Standard_Boolean GetSHUOMode() const; - + void SetSHUOMode(const Standard_Boolean theSHUOMode) { mySHUOMode = theSHUOMode; } + + Standard_Boolean GetSHUOMode() const { return mySHUOMode; } + //! Set dimtolmode for indicate write D>s or not. - Standard_EXPORT void SetDimTolMode (const Standard_Boolean dimtolmode); - - Standard_EXPORT Standard_Boolean GetDimTolMode() const; - + void SetDimTolMode(const Standard_Boolean theDimTolMode) { myGDTMode = theDimTolMode; }; + + Standard_Boolean GetDimTolMode() const { return myGDTMode; } + //! Set dimtolmode for indicate write D>s or not. - Standard_EXPORT void SetMaterialMode (const Standard_Boolean matmode); - - Standard_EXPORT Standard_Boolean GetMaterialMode() const; + void SetMaterialMode(const Standard_Boolean theMaterialMode) { myMatMode = theMaterialMode; } + + Standard_Boolean GetMaterialMode() const { return myMatMode; } protected: - + //! Transfers labels to a STEP model //! Returns True if translation is OK - //! isExternFile setting from TransferExternFiles method - Standard_EXPORT Standard_Boolean Transfer (STEPControl_Writer& wr, - const TDF_LabelSequence& labels, - const STEPControl_StepModelType mode = STEPControl_AsIs, - const Standard_CString multi = 0, - const Standard_Boolean isExternFile = Standard_False, - const Message_ProgressRange& theProgress = Message_ProgressRange()) ; - + //! isExternFile setting from transferExternFiles method + Standard_Boolean transfer(STEPControl_Writer& theWriter, + const TDF_LabelSequence& theLabels, + const STEPControl_StepModelType theMode = STEPControl_AsIs, + const Standard_CString theIsMulti = 0, + const Standard_Boolean isExternFile = Standard_False, + const Message_ProgressRange& theProgress = Message_ProgressRange()); + //! Parses assembly structure of label L, writes all the simple //! shapes each to its own file named by name of its label plus //! prefix //! Returns shape representing that assembly structure //! in the form of nested empty compounds (and a sequence of //! labels which are newly written nodes of this assembly) - Standard_EXPORT TopoDS_Shape TransferExternFiles (const TDF_Label& L, - const STEPControl_StepModelType mode, - TDF_LabelSequence& Lseq, - const Standard_CString prefix = "", - const Message_ProgressRange& theProgress = Message_ProgressRange()); - + TopoDS_Shape transferExternFiles(const TDF_Label& theLabel, + const STEPControl_StepModelType theMode, + TDF_LabelSequence& theLabelSeq, + const Standard_CString thePrefix = "", + const Message_ProgressRange& theProgress = Message_ProgressRange()); + //! Write external references to STEP - Standard_EXPORT Standard_Boolean WriteExternRefs (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const; - + Standard_Boolean writeExternRefs(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const; + //! Write colors assigned to specified labels, to STEP model - Standard_EXPORT Standard_Boolean WriteColors (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels); - + Standard_Boolean writeColors(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels); + //! Write names assigned to specified labels, to STEP model - Standard_EXPORT Standard_Boolean WriteNames (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const; - + Standard_Boolean writeNames(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const; + //! Write D>s assigned to specified labels, to STEP model - Standard_EXPORT Standard_Boolean WriteDGTs (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const; - - //! Write D>s assigned to specified labels, to STEP model, according AP242 - Standard_EXPORT Standard_Boolean WriteDGTsAP242 (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels); + Standard_Boolean writeDGTs(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const; + + //! Write D>s assigned to specified labels, to STEP model, according AP242 + Standard_Boolean writeDGTsAP242(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels); //! Write materials assigned to specified labels, to STEP model - Standard_EXPORT Standard_Boolean WriteMaterials (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const; - + Standard_Boolean writeMaterials(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const; + //! Write validation properties assigned to specified labels, //! to STEP model - Standard_EXPORT Standard_Boolean WriteValProps (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels, const Standard_CString multi) const; - + Standard_Boolean writeValProps(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels, + const Standard_CString theIsMulti) const; + //! Write layers assigned to specified labels, to STEP model - Standard_EXPORT Standard_Boolean WriteLayers (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const; - + Standard_Boolean writeLayers(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels) const; + //! Write SHUO assigned to specified component, to STEP model - Standard_EXPORT Standard_Boolean WriteSHUOs (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels); + Standard_Boolean writeSHUOs(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theLabels); //! Finds length units located in root of label //! If it exists, initializes local length unit from it //! Else initializes according to Cascade length unit - Standard_EXPORT void prepareUnit(const TDF_Label& theLabel, - const Handle(StepData_StepModel)& theModel); + void prepareUnit(const TDF_Label& theLabel, + const Handle(StepData_StepModel)& theModel); + + Handle(StepRepr_ShapeAspect) writeShapeAspect(const Handle(XSControl_WorkSession)& theWS, + const TDF_Label theLabel, + const TopoDS_Shape theShape, + Handle(StepRepr_RepresentationContext)& theRC, + Handle(StepAP242_GeometricItemSpecificUsage)& theGISU); + + void writePresentation(const Handle(XSControl_WorkSession)& theWS, + const TopoDS_Shape& thePresentation, + const Handle(TCollection_HAsciiString)& thePrsName, + const Standard_Boolean theHasSemantic, + const Standard_Boolean theHasPlane, + const gp_Ax2& theAnnotationPlane, + const gp_Pnt& theTextPosition, + const Handle(Standard_Transient) theDimension); + + Handle(StepDimTol_Datum) writeDatumAP242(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theShapeL, + const TDF_Label& theDatumL, + const Standard_Boolean isFirstDTarget, + const Handle(StepDimTol_Datum) theWrittenDatum); + + void writeToleranceZone(const Handle(XSControl_WorkSession)& theWS, + const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject, + const Handle(StepDimTol_GeometricTolerance)& theEntity, + const Handle(StepRepr_RepresentationContext)& theRC); + + void writeGeomTolerance(const Handle(XSControl_WorkSession)& theWS, + const TDF_LabelSequence& theShapeSeqL, + const TDF_Label& theGeomTolL, + const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem, + const Handle(StepRepr_RepresentationContext)& theRC); private: - Standard_EXPORT Handle(StepRepr_ShapeAspect) WriteShapeAspect(const Handle(XSControl_WorkSession) &WS, - const TDF_Label theLabel, const TopoDS_Shape theShape, Handle(StepRepr_RepresentationContext)& theRC, - Handle(StepAP242_GeometricItemSpecificUsage)& theGISU); - - Standard_EXPORT void WritePresentation(const Handle(XSControl_WorkSession)& WS, - const TopoDS_Shape& thePresentation, - const Handle(TCollection_HAsciiString)& thePrsName, - const Standard_Boolean hasSemantic, - const Standard_Boolean hasPlane, - const gp_Ax2& theAnnotationPlane, - const gp_Pnt& theTextPosition, - const Handle(Standard_Transient) theDimension); - - Standard_EXPORT Handle(StepDimTol_Datum) WriteDatumAP242(const Handle(XSControl_WorkSession)& WS, - const TDF_LabelSequence& theShapeL, - const TDF_Label& theDatumL, - const Standard_Boolean isFirstDTarget, - const Handle(StepDimTol_Datum) theWrittenDatum); - - Standard_EXPORT void WriteToleranceZone(const Handle(XSControl_WorkSession) &WS, const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject, - const Handle(StepDimTol_GeometricTolerance)& theEntity, const Handle(StepRepr_RepresentationContext)& theRC); - - Standard_EXPORT void WriteGeomTolerance(const Handle(XSControl_WorkSession)& WS, - const TDF_LabelSequence& theShapeSeqL, - const TDF_Label& theGeomTolL, - const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem, - const Handle(StepRepr_RepresentationContext)& theRC); - -private: - - STEPControl_Writer myWriter; NCollection_DataMap myFiles; + TDF_LabelMap myRootLabels; STEPCAFControl_DataMapOfLabelShape myLabels; STEPCAFControl_DataMapOfLabelExternFile myLabEF; + STEPCAFControl_DataMapOfLabelShape myPureRefLabels; Standard_Boolean myColorMode; Standard_Boolean myNameMode; Standard_Boolean myLayerMode; @@ -272,7 +288,4 @@ private: }; - - - #endif // _STEPCAFControl_Writer_HeaderFile diff --git a/src/XCAFDoc/XCAFDoc_ColorTool.cxx b/src/XCAFDoc/XCAFDoc_ColorTool.cxx index 42e924c171..7cd379f129 100644 --- a/src/XCAFDoc/XCAFDoc_ColorTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ColorTool.cxx @@ -89,7 +89,7 @@ Standard_Boolean XCAFDoc_ColorTool::IsColor (const TDF_Label& lab) const //======================================================================= Standard_Boolean XCAFDoc_ColorTool::GetColor (const TDF_Label& lab, - Quantity_Color& col) const + Quantity_Color& col) { Quantity_ColorRGBA aCol; Standard_Boolean isDone = GetColor(lab, aCol); @@ -104,10 +104,8 @@ Standard_Boolean XCAFDoc_ColorTool::GetColor (const TDF_Label& lab, //======================================================================= Standard_Boolean XCAFDoc_ColorTool::GetColor(const TDF_Label& lab, - Quantity_ColorRGBA& col) const + Quantity_ColorRGBA& col) { - if (lab.Father() != Label()) return Standard_False; - Handle(XCAFDoc_Color) ColorAttribute; if (!lab.FindAttribute(XCAFDoc_Color::GetID(), ColorAttribute)) return Standard_False; @@ -514,7 +512,7 @@ XCAFDoc_ColorTool::XCAFDoc_ColorTool() //purpose : //======================================================================= -Standard_Boolean XCAFDoc_ColorTool::IsVisible (const TDF_Label& L) const +Standard_Boolean XCAFDoc_ColorTool::IsVisible (const TDF_Label& L) { Handle(TDataStd_UAttribute) aUAttr; return (!L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)); diff --git a/src/XCAFDoc/XCAFDoc_ColorTool.hxx b/src/XCAFDoc/XCAFDoc_ColorTool.hxx index b5222d912d..13270cec93 100644 --- a/src/XCAFDoc/XCAFDoc_ColorTool.hxx +++ b/src/XCAFDoc/XCAFDoc_ColorTool.hxx @@ -72,12 +72,12 @@ public: //! Returns color defined by label lab //! Returns False if the label is not in colortable //! or does not define a color - Standard_EXPORT Standard_Boolean GetColor (const TDF_Label& lab, Quantity_Color& col) const; + Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& lab, Quantity_Color& col); //! Returns color defined by label lab //! Returns False if the label is not in colortable //! or does not define a color - Standard_EXPORT Standard_Boolean GetColor(const TDF_Label& lab, Quantity_ColorRGBA& col) const; + Standard_EXPORT static Standard_Boolean GetColor(const TDF_Label& lab, Quantity_ColorRGBA& col); //! Finds a color definition in a colortable and returns //! its label if found @@ -150,11 +150,11 @@ public: //! Returns color assigned to as //! Returns False if no such color is assigned - Standard_EXPORT Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_Color& color); + Standard_EXPORT static Standard_Boolean GetColor (const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_Color& color); //! Returns color assigned to as //! Returns False if no such color is assigned - Standard_EXPORT Standard_Boolean GetColor(const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color); + Standard_EXPORT static Standard_Boolean GetColor(const TDF_Label& L, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color); //! Sets a link with GUID defined by (see //! XCAFDoc::ColorRefGUID()) from label to color @@ -198,7 +198,7 @@ public: Standard_EXPORT Standard_Boolean GetColor(const TopoDS_Shape& S, const XCAFDoc_ColorType type, Quantity_ColorRGBA& color); //! Return TRUE if object on this label is visible, FALSE if invisible. - Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& L) const; + Standard_EXPORT static Standard_Boolean IsVisible (const TDF_Label& L); //! Set the visibility of object on label. Do nothing if there no any object. //! Set UAttribute with corresponding GUID. diff --git a/src/XCAFDoc/XCAFDoc_DimTolTool.cxx b/src/XCAFDoc/XCAFDoc_DimTolTool.cxx index 3d54642338..b396f408dd 100644 --- a/src/XCAFDoc/XCAFDoc_DimTolTool.cxx +++ b/src/XCAFDoc/XCAFDoc_DimTolTool.cxx @@ -503,7 +503,7 @@ TDF_Label XCAFDoc_DimTolTool::SetDimTol(const TDF_Label& L, Standard_Boolean XCAFDoc_DimTolTool::GetRefShapeLabel(const TDF_Label& theL, TDF_LabelSequence& theShapeLFirst, - TDF_LabelSequence& theShapeLSecond) const + TDF_LabelSequence& theShapeLSecond) { theShapeLFirst.Clear(); theShapeLSecond.Clear(); @@ -855,7 +855,7 @@ Standard_Boolean XCAFDoc_DimTolTool::GetDatum(const TDF_Label& theDatumL, //======================================================================= Standard_Boolean XCAFDoc_DimTolTool::GetDatumOfTolerLabels(const TDF_Label& theDimTolL, - TDF_LabelSequence& theDatums) const + TDF_LabelSequence& theDatums) { Handle(XCAFDoc_GraphNode) aNode; if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) ) @@ -874,7 +874,7 @@ Standard_Boolean XCAFDoc_DimTolTool::GetDatumOfTolerLabels(const TDF_Label& theD //======================================================================= Standard_Boolean XCAFDoc_DimTolTool::GetDatumWithObjectOfTolerLabels(const TDF_Label& theDimTolL, - TDF_LabelSequence& theDatums) const + TDF_LabelSequence& theDatums) { Handle(XCAFDoc_GraphNode) aNode; if( !theDimTolL.FindAttribute(XCAFDoc::DatumTolRefGUID(),aNode) ) diff --git a/src/XCAFDoc/XCAFDoc_DimTolTool.hxx b/src/XCAFDoc/XCAFDoc_DimTolTool.hxx index 1282719f1c..78380f0853 100644 --- a/src/XCAFDoc/XCAFDoc_DimTolTool.hxx +++ b/src/XCAFDoc/XCAFDoc_DimTolTool.hxx @@ -155,9 +155,9 @@ public: //! Gets all shape labels referred by theL label of the GD&T table. //! Returns False if there are no shape labels added to the sequences. - Standard_EXPORT Standard_Boolean GetRefShapeLabel (const TDF_Label& theL, - TDF_LabelSequence& theShapeLFirst, - TDF_LabelSequence& theShapeLSecond) const; + Standard_EXPORT static Standard_Boolean GetRefShapeLabel (const TDF_Label& theL, + TDF_LabelSequence& theShapeLFirst, + TDF_LabelSequence& theShapeLSecond); //! Returns dimension tolerance assigned to theDimTolL label. //! Returns False if no such dimension tolerance is assigned. @@ -215,12 +215,12 @@ public: Handle(TCollection_HAsciiString)& theIdentification) const; //! Returns all Datum labels defined for theDimTolL label. - Standard_EXPORT Standard_Boolean GetDatumOfTolerLabels (const TDF_Label& theDimTolL, - TDF_LabelSequence& theDatums) const; + Standard_EXPORT static Standard_Boolean GetDatumOfTolerLabels (const TDF_Label& theDimTolL, + TDF_LabelSequence& theDatums); //! Returns all Datum labels with XCAFDimTolObjects_DatumObject defined for label theDimTolL. - Standard_EXPORT Standard_Boolean GetDatumWithObjectOfTolerLabels (const TDF_Label& theDimTolL, - TDF_LabelSequence& theDatums) const; + Standard_EXPORT static Standard_Boolean GetDatumWithObjectOfTolerLabels (const TDF_Label& theDimTolL, + TDF_LabelSequence& theDatums); //! Returns all GeomToleranses labels defined for theDatumL label. Standard_EXPORT Standard_Boolean GetTolerOfDatumLabels (const TDF_Label& theDatumL, diff --git a/src/XCAFDoc/XCAFDoc_LayerTool.cxx b/src/XCAFDoc/XCAFDoc_LayerTool.cxx index 42917fe4e9..52b781c546 100644 --- a/src/XCAFDoc/XCAFDoc_LayerTool.cxx +++ b/src/XCAFDoc/XCAFDoc_LayerTool.cxx @@ -416,20 +416,20 @@ Handle(TColStd_HSequenceOfExtendedString) XCAFDoc_LayerTool::GetLayers(const TDF //function : GetShapesOfLayer //purpose : //======================================================================= - -void XCAFDoc_LayerTool::GetShapesOfLayer(const TDF_Label& layerL, - TDF_LabelSequence& ShLabels) const +void XCAFDoc_LayerTool::GetShapesOfLayer(const TDF_Label& theLayerL, + TDF_LabelSequence& theShLabels) { - ShLabels.Clear(); + theShLabels.Clear(); Handle(XCAFDoc_GraphNode) aGNode; - if ( layerL.FindAttribute( XCAFDoc::LayerRefGUID(), aGNode) ) { - for (Standard_Integer i = 1; i <= aGNode->NbChildren(); i++) { - ShLabels.Append( aGNode->GetChild(i)->Label() ); + if (theLayerL.FindAttribute(XCAFDoc::LayerRefGUID(), aGNode)) + { + for (Standard_Integer aChildInd = 1; aChildInd <= aGNode->NbChildren(); aChildInd++) + { + theShLabels.Append(aGNode->GetChild(aChildInd)->Label()); } } } - //======================================================================= //function : IsVisible //purpose : diff --git a/src/XCAFDoc/XCAFDoc_LayerTool.hxx b/src/XCAFDoc/XCAFDoc_LayerTool.hxx index 386cf9c204..086465a7df 100644 --- a/src/XCAFDoc/XCAFDoc_LayerTool.hxx +++ b/src/XCAFDoc/XCAFDoc_LayerTool.hxx @@ -135,7 +135,7 @@ public: Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetLayers (const TDF_Label& L); //! Return sequanese of shape labels that assigned with layers to . - Standard_EXPORT void GetShapesOfLayer (const TDF_Label& layerL, TDF_LabelSequence& ShLabels) const; + Standard_EXPORT static void GetShapesOfLayer (const TDF_Label& theLayerL, TDF_LabelSequence& theShLabels); //! Return TRUE if layer is visible, FALSE if invisible. Standard_EXPORT Standard_Boolean IsVisible (const TDF_Label& layerL) const; diff --git a/src/XCAFDoc/XCAFDoc_MaterialTool.cxx b/src/XCAFDoc/XCAFDoc_MaterialTool.cxx index 2950189d86..74e8693bc2 100644 --- a/src/XCAFDoc/XCAFDoc_MaterialTool.cxx +++ b/src/XCAFDoc/XCAFDoc_MaterialTool.cxx @@ -184,7 +184,7 @@ Standard_Boolean XCAFDoc_MaterialTool::GetMaterial(const TDF_Label& MatL, Handle(TCollection_HAsciiString)& aDescription, Standard_Real& aDensity, Handle(TCollection_HAsciiString)& aDensName, - Handle(TCollection_HAsciiString)& aDensValType) const + Handle(TCollection_HAsciiString)& aDensValType) { Handle(XCAFDoc_Material) MatAttr; if(!MatL.FindAttribute(XCAFDoc_Material::GetID(),MatAttr)) { diff --git a/src/XCAFDoc/XCAFDoc_MaterialTool.hxx b/src/XCAFDoc/XCAFDoc_MaterialTool.hxx index d9e12b9aff..069b3fc5ca 100644 --- a/src/XCAFDoc/XCAFDoc_MaterialTool.hxx +++ b/src/XCAFDoc/XCAFDoc_MaterialTool.hxx @@ -76,7 +76,7 @@ public: //! Returns Material assigned to //! Returns False if no such Material is assigned - Standard_EXPORT Standard_Boolean GetMaterial (const TDF_Label& MatL, Handle(TCollection_HAsciiString)& aName, Handle(TCollection_HAsciiString)& aDescription, Standard_Real& aDensity, Handle(TCollection_HAsciiString)& aDensName, Handle(TCollection_HAsciiString)& aDensValType) const; + Standard_EXPORT static Standard_Boolean GetMaterial (const TDF_Label& MatL, Handle(TCollection_HAsciiString)& aName, Handle(TCollection_HAsciiString)& aDescription, Standard_Real& aDensity, Handle(TCollection_HAsciiString)& aDensName, Handle(TCollection_HAsciiString)& aDensValType); //! Find referred material and return density from it //! if no material --> return 0 diff --git a/src/XCAFDoc/XCAFDoc_VisMaterialTool.cxx b/src/XCAFDoc/XCAFDoc_VisMaterialTool.cxx index 4bfc4c6cc0..af6e9b9113 100644 --- a/src/XCAFDoc/XCAFDoc_VisMaterialTool.cxx +++ b/src/XCAFDoc/XCAFDoc_VisMaterialTool.cxx @@ -79,13 +79,10 @@ const Handle(XCAFDoc_ShapeTool)& XCAFDoc_VisMaterialTool::ShapeTool() //function : GetMaterial //purpose : //======================================================================= -Handle(XCAFDoc_VisMaterial) XCAFDoc_VisMaterialTool::GetMaterial (const TDF_Label& theMatLabel) const +Handle(XCAFDoc_VisMaterial) XCAFDoc_VisMaterialTool::GetMaterial(const TDF_Label& theMatLabel) { Handle(XCAFDoc_VisMaterial) aMatAttrib; - if (theMatLabel.Father() == Label()) - { - theMatLabel.FindAttribute (XCAFDoc_VisMaterial::GetID(), aMatAttrib); - } + theMatLabel.FindAttribute(XCAFDoc_VisMaterial::GetID(), aMatAttrib); return aMatAttrib; } @@ -214,8 +211,7 @@ Standard_Boolean XCAFDoc_VisMaterialTool::GetShapeMaterial (const TDF_Label& the Handle(XCAFDoc_VisMaterial) XCAFDoc_VisMaterialTool::GetShapeMaterial (const TDF_Label& theShapeLabel) { TDF_Label aMatLabel; - return Label().HasChild() // do not waste time on shape attributes if materials map is empty - && GetShapeMaterial (theShapeLabel, aMatLabel) + return GetShapeMaterial (theShapeLabel, aMatLabel) ? GetMaterial (aMatLabel) : Handle(XCAFDoc_VisMaterial)(); } diff --git a/src/XCAFDoc/XCAFDoc_VisMaterialTool.hxx b/src/XCAFDoc/XCAFDoc_VisMaterialTool.hxx index e99196851e..6f76a94c04 100644 --- a/src/XCAFDoc/XCAFDoc_VisMaterialTool.hxx +++ b/src/XCAFDoc/XCAFDoc_VisMaterialTool.hxx @@ -56,7 +56,7 @@ public: Standard_Boolean IsMaterial (const TDF_Label& theLabel) const { return !GetMaterial (theLabel).IsNull(); } //! Returns Material defined by specified Label, or NULL if the label is not in Material Table. - Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetMaterial (const TDF_Label& theMatLabel) const; + Standard_EXPORT static Handle(XCAFDoc_VisMaterial) GetMaterial (const TDF_Label& theMatLabel); //! Adds Material definition to a Material Table and returns its Label. Standard_EXPORT TDF_Label AddMaterial (const Handle(XCAFDoc_VisMaterial)& theMat, @@ -88,7 +88,7 @@ public: Standard_EXPORT static Standard_Boolean GetShapeMaterial (const TDF_Label& theShapeLabel, TDF_Label& theMaterialLabel); //! Returns material assigned to the shape label. - Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetShapeMaterial (const TDF_Label& theShapeLabel); + Standard_EXPORT static Handle(XCAFDoc_VisMaterial) GetShapeMaterial (const TDF_Label& theShapeLabel); //! Sets a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material label. //! @param theShape [in] shape diff --git a/tests/bugs/step/bug33317 b/tests/bugs/step/bug33317 new file mode 100644 index 0000000000..0500681d8c --- /dev/null +++ b/tests/bugs/step/bug33317 @@ -0,0 +1,32 @@ +puts "========================" +puts "0033317: Data Exchange, Step Export - Ignoring color attached to the reference shape label" +puts "========================" + +pload OCAF + +Close D -silent +Close D1 -silent + +set TempFilename ${imagedir}/${casename}_temp.stp + +# Open document +XOpen [locate_data_file bug33317_solids_7_7_0.xml] D + +# Get colors +set colors_old [XGetShapeColor D 0:1:1:1 generic] + +# Write to STEP +WriteStep D ${TempFilename} + +# Read and check +ReadStep D1 ${TempFilename} + +set colors_new [XGetShapeColor D1 0:1:1:1:1 generic] +if { [string equal ${colors_new} ${colors_old}] == -1 } { + puts "ERROR: OCC33317 is reproduced while STEP export." +} + +# Clear temp file +file delete -force $TempFilename +Close D +Close D1