0023403: Crash when parsing an expression with lexical error
[occt.git] / src / STEPCAFControl / STEPCAFControl_Writer.cxx
CommitLineData
b311480e 1// Created on: 2000-08-15
2// Created by: Andrey BETENEV
3// Copyright (c) 2000-2012 OPEN CASCADE SAS
7fd59977 4//
b311480e 5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
7fd59977 12//
b311480e 13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20// CURRENT LIMITATIONS:
7fd59977 21// when val props and names assigned to instance of
22// component in assembly, it is in fact supposed that only one CDSR corresponds
23// to such shape. This can be wrong and should be handled more carefully
24// (analysis of SDRs which the CDSR links should be done)
7fd59977 25// Names and validation props are supported for top-level shapes only
26
27#include <STEPCAFControl_Writer.ixx>
28#include <STEPControl_StepModelType.hxx>
29#include <XCAFDoc_ShapeTool.hxx>
30#include <TDF_LabelSequence.hxx>
31#include <TopoDS_Shape.hxx>
32#include <XCAFPrs_DataMapOfShapeStyle.hxx>
33#include <XCAFPrs.hxx>
34#include <XCAFPrs_DataMapOfStyleShape.hxx>
35#include <XCAFPrs_Style.hxx>
36#include <XCAFPrs_DataMapIteratorOfDataMapOfStyleShape.hxx>
37#include <TopTools_SequenceOfShape.hxx>
38#include <TopoDS_Iterator.hxx>
39#include <STEPConstruct_Styles.hxx>
40#include <XCAFDoc_ColorTool.hxx>
41#include <STEPConstruct.hxx>
42#include <TopTools_MapOfShape.hxx>
43#include <XSControl_TransferWriter.hxx>
44#include <TDataStd_Name.hxx>
45#include <StepShape_ShapeDefinitionRepresentation.hxx>
46#include <TransferBRep_ShapeMapper.hxx>
47#include <TransferBRep.hxx>
48#include <StepRepr_PropertyDefinition.hxx>
49#include <StepBasic_ProductDefinition.hxx>
50#include <StepBasic_Product.hxx>
51#include <TCollection_HAsciiString.hxx>
52#include <TCollection_AsciiString.hxx>
53#include <Transfer_FinderProcess.hxx>
54#include <StepBasic_ProductDefinitionFormation.hxx>
55#include <XCAFDoc_DocumentTool.hxx>
56#include <TDF_Label.hxx>
57#include <STEPCAFControl_Controller.hxx>
58#include <STEPCAFControl_IteratorOfDictionaryOfExternFile.hxx>
59#include <STEPConstruct_ExternRefs.hxx>
60#include <Interface_Static.hxx>
61#include <TopoDS_Compound.hxx>
62#include <BRep_Builder.hxx>
63#include <Transfer_ActorOfFinderProcess.hxx>
64#include <STEPCAFControl_ActorWrite.hxx>
65#include <STEPConstruct_ValidationProps.hxx>
66#include <XCAFDoc_Area.hxx>
67#include <XCAFDoc_Volume.hxx>
68#include <XCAFDoc_Centroid.hxx>
69#include <StepShape_ContextDependentShapeRepresentation.hxx>
70#include <StepRepr_ProductDefinitionShape.hxx>
71#include <StepBasic_ProductDefinitionRelationship.hxx>
72#include <XCAFDoc_GraphNode.hxx>
73#include <XCAFDoc_LayerTool.hxx>
74#include <StepVisual_PresentationLayerAssignment.hxx>
75#include <XCAFDoc.hxx>
76#include <StepVisual_HArray1OfLayeredItem.hxx>
77#include <TColStd_HSequenceOfTransient.hxx>
78#include <TDF_Tool.hxx>
79#include <Message_Messenger.hxx>
80
81#include <Transfer_Binder.hxx>
82#include <Transfer_TransientListBinder.hxx>
83#include <StepVisual_InvisibleItem.hxx>
84#include <TDataStd_UAttribute.hxx>
85#include <StepVisual_Invisibility.hxx>
86#include <StepVisual_HArray1OfInvisibleItem.hxx>
87#include <HeaderSection_FileSchema.hxx>
88#include <StepData_StepModel.hxx>
89#include <StepAP214_Protocol.hxx>
90#include <OSD_Path.hxx>
91#include <XSControl_WorkSession.hxx>
92#include <StepRepr_HArray1OfRepresentationItem.hxx>
93#include <MoniTool_DataMapIteratorOfDataMapOfShapeTransient.hxx>
94#include <StepRepr_Representation.hxx>
95#include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
96#include <Quantity_TypeOfColor.hxx>
97#include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
98#include <StepVisual_PresentationStyleAssignment.hxx>
99#include <StepVisual_StyledItem.hxx>
100#include <StepVisual_PresentationStyleByContext.hxx>
101#include <StepVisual_HArray1OfPresentationStyleSelect.hxx>
102#include <TDF_AttributeSequence.hxx>
103#include <TColStd_MapOfTransient.hxx>
104// #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
105#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
106#include <Interface_EntityIterator.hxx>
107#include <StepRepr_SpecifiedHigherUsageOccurrence.hxx>
108
109// added by skl 15.01.2004 for D&GT writing
110#include <XCAFDoc_DimTolTool.hxx>
111#include <XCAFDoc_DimTol.hxx>
112#include <XCAFDoc_Datum.hxx>
113#include <STEPConstruct_DataMapOfAsciiStringTransient.hxx>
114#include <STEPConstruct_DataMapOfPointTransient.hxx>
115#include <StepBasic_MeasureValueMember.hxx>
116#include <StepBasic_SiUnitAndLengthUnit.hxx>
117#include <StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext.hxx>
118#include <StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx.hxx>
119#include <StepBasic_LengthMeasureWithUnit.hxx>
120#include <StepShape_EdgeCurve.hxx>
121#include <StepShape_AdvancedFace.hxx>
122#include <StepShape_OrientedEdge.hxx>
123#include <StepShape_EdgeLoop.hxx>
124#include <StepShape_FaceBound.hxx>
125#include <StepShape_ConnectedFaceSet.hxx>
126#include <StepShape_ShapeRepresentation.hxx>
127#include <StepShape_DimensionalSize.hxx>
128#include <StepShape_ShapeDimensionRepresentation.hxx>
129#include <StepShape_DimensionalCharacteristicRepresentation.hxx>
130#include <StepRepr_ShapeAspect.hxx>
131#include <StepRepr_ShapeAspectRelationship.hxx>
132#include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
133//#include <StepRepr_CompoundItemDefinition.hxx>
134//#include <StepRepr_CompoundItemDefinitionMember.hxx>
135#include <StepRepr_ValueRange.hxx>
136#include <StepData_Logical.hxx>
137#include <StepDimTol_DatumFeature.hxx>
138#include <StepDimTol_Datum.hxx>
139#include <StepDimTol_DatumReference.hxx>
140#include <StepDimTol_HArray1OfDatumReference.hxx>
141#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
142#include <StepDimTol_ModifiedGeometricTolerance.hxx>
143#include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
144#include <StepDimTol_AngularityTolerance.hxx>
145#include <StepDimTol_CircularRunoutTolerance.hxx>
146#include <StepDimTol_CoaxialityTolerance.hxx>
147#include <StepDimTol_ConcentricityTolerance.hxx>
148#include <StepDimTol_ParallelismTolerance.hxx>
149#include <StepDimTol_PerpendicularityTolerance.hxx>
150#include <StepDimTol_SymmetryTolerance.hxx>
151#include <StepDimTol_TotalRunoutTolerance.hxx>
152#include <StepDimTol_CylindricityTolerance.hxx>
153#include <StepDimTol_FlatnessTolerance.hxx>
154#include <StepDimTol_LineProfileTolerance.hxx>
155#include <StepDimTol_PositionTolerance.hxx>
156#include <StepDimTol_RoundnessTolerance.hxx>
157#include <StepDimTol_StraightnessTolerance.hxx>
158#include <StepDimTol_SurfaceProfileTolerance.hxx>
159#include <TColStd_HArray1OfReal.hxx>
160#include <TColStd_HArray1OfTransient.hxx>
161
162// added by skl 12.02.2004 for writing materials
163#include <XCAFDoc_MaterialTool.hxx>
164#include <XCAFDoc_Material.hxx>
165#include <TDataStd_TreeNode.hxx>
166#include <StepRepr_DescriptiveRepresentationItem.hxx>
167#include <StepBasic_SiUnitAndMassUnit.hxx>
168#include <StepBasic_DerivedUnitElement.hxx>
169#include <StepBasic_HArray1OfDerivedUnitElement.hxx>
170#include <StepBasic_DerivedUnit.hxx>
171#include <StepRepr_MeasureRepresentationItem.hxx>
1d2b1ccb 172#include <StepBasic_ProductDefinition.hxx>
7fd59977 173
174//=======================================================================
175//function : GetLabelName
176//purpose : auxilary function: take name of label and append it to str
177//=======================================================================
178static Standard_Boolean GetLabelName (const TDF_Label &L, Handle(TCollection_HAsciiString) &str)
179{
180 Handle(TDataStd_Name) N;
181 if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) return Standard_False;
182 TCollection_ExtendedString name = N->Get();
183 if ( name.Length() <=0 ) return Standard_False;
184
185 // set name, converting it to Ascii and removing spaces
186 TCollection_AsciiString buf ( name, '?' );
187 buf.LeftAdjust();
188 buf.RightAdjust();
189 buf.ChangeAll(' ','_');
190 str->AssignCat ( buf.ToCString() );
191 return Standard_True;
192}
193
194
195//=======================================================================
196//function : STEPCAFControl_Writer
197//purpose :
198//=======================================================================
199
200STEPCAFControl_Writer::STEPCAFControl_Writer () :
201 myColorMode( Standard_True ),
202 myNameMode ( Standard_True ),
203 myLayerMode( Standard_True ),
204 myPropsMode( Standard_True ),
205 mySHUOMode ( Standard_True ),
206 myDGTMode ( Standard_True ),
207 myMatMode ( Standard_True )
208{
209 STEPCAFControl_Controller::Init();
210 Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
211 Init ( WS );
212}
213
214
215//=======================================================================
216//function : STEPCAFControl_Writer
217//purpose :
218//=======================================================================
219
220STEPCAFControl_Writer::STEPCAFControl_Writer (const Handle(XSControl_WorkSession)& WS,
221 const Standard_Boolean scratch)
222{
223 STEPCAFControl_Controller::Init();
224 Init ( WS, scratch );
225 myColorMode = Standard_True;
226 myNameMode = Standard_True;
227 myLayerMode = Standard_True;
228 myPropsMode = Standard_True;
229 mySHUOMode = Standard_True;
230}
231
232
233//=======================================================================
234//function : Init
235//purpose :
236//=======================================================================
237
238void STEPCAFControl_Writer::Init (const Handle(XSControl_WorkSession)& WS,
239 const Standard_Boolean scratch)
240{
241 WS->SelectNorm ( "STEP" );
242 myWriter.SetWS (WS,scratch);
243 myFiles = new STEPCAFControl_DictionaryOfExternFile;
244 myLabEF.Clear();
245 myLabels.Clear();
246}
247
248
249//=======================================================================
250//function : Write
251//purpose :
252//=======================================================================
253
254IFSelect_ReturnStatus STEPCAFControl_Writer::Write (const Standard_CString filename)
255{
256 IFSelect_ReturnStatus status = myWriter.Write ( filename );
257
258 // get directory name of the main file
259 OSD_Path mainfile ( filename );
260 mainfile.SetName ( "" );
261 mainfile.SetExtension ( "" );
262 TCollection_AsciiString dpath;
263 mainfile.SystemName ( dpath );
264
265 STEPCAFControl_IteratorOfDictionaryOfExternFile it ( myFiles );
266 for ( ; it.More(); it.Next() ) {
267 Handle(STEPCAFControl_ExternFile) EF = it.Value();
268 if ( EF->GetWriteStatus() != IFSelect_RetVoid ) continue;
269
270 // construct extern file name
271 TCollection_AsciiString fname = OSD_Path::AbsolutePath ( dpath, EF->GetName()->String() );
272 if ( fname.Length() <= 0 ) fname = EF->GetName()->String();
273#ifdef DEB
274 cout << "Writing external file: " << fname.ToCString() << endl;
275#endif
276
277 EF->SetWriteStatus ( EF->GetWS()->SendAll ( fname.ToCString() ) );
278 }
279
280 return status;
281}
282
283
284//=======================================================================
285//function : Transfer
286//purpose :
287//=======================================================================
288
289Standard_Boolean STEPCAFControl_Writer::Transfer (const Handle(TDocStd_Document) &doc,
290 const STEPControl_StepModelType mode,
291 const Standard_CString multi)
292{
293 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
294 if ( STool.IsNull() ) return Standard_False;
295
296 TDF_LabelSequence labels;
297 STool->GetFreeShapes ( labels );
298 return Transfer ( myWriter, labels, mode, multi );
299}
300
301
302//=======================================================================
303//function : Transfer
304//purpose :
305//=======================================================================
306
307Standard_Boolean STEPCAFControl_Writer::Transfer (const TDF_Label &L,
308 const STEPControl_StepModelType mode,
309 const Standard_CString multi)
310{
311 TDF_LabelSequence labels;
312 labels.Append ( L );
313 return Transfer ( myWriter, labels, mode, multi );
314}
315
316
317//=======================================================================
318//function : Perform
319//purpose :
320//=======================================================================
321
322Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
323 const Standard_CString filename)
324{
325 if ( ! Transfer ( doc ) ) return Standard_False;
326 return Write ( filename ) == IFSelect_RetDone;
327}
328
329
330//=======================================================================
331//function : Perform
332//purpose :
333//=======================================================================
334
335Standard_Boolean STEPCAFControl_Writer::Perform (const Handle(TDocStd_Document) &doc,
336 const TCollection_AsciiString &filename)
337{
338 if ( ! Transfer ( doc ) ) return Standard_False;
339 return Write ( filename.ToCString() ) == IFSelect_RetDone;
340}
341
342
343//=======================================================================
344//function : ExternFiles
345//purpose :
346//=======================================================================
347
348const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Writer::ExternFiles () const
349{
350 return myFiles;
351}
352
353
354//=======================================================================
355//function : ExternFile
356//purpose :
357//=======================================================================
358
359Standard_Boolean STEPCAFControl_Writer::ExternFile (const TDF_Label &L,
360 Handle(STEPCAFControl_ExternFile) &ef) const
361{
362 ef.Nullify();
363 if ( ! myLabEF.IsBound ( L ) ) return Standard_False;
364 ef = myLabEF.Find ( L );
365 return Standard_True;
366}
367
368
369//=======================================================================
370//function : ExternFile
371//purpose :
372//=======================================================================
373
374Standard_Boolean STEPCAFControl_Writer::ExternFile (const Standard_CString name,
375 Handle(STEPCAFControl_ExternFile) &ef) const
376{
377 ef.Nullify();
378 if ( ! myFiles.IsNull() || ! myFiles->HasItem ( name ) )
379 return Standard_False;
380 ef = myFiles->Item ( name );
381 return Standard_True;
382}
383
384
385//=======================================================================
386//function : Writer
387//purpose :
388//=======================================================================
389
390STEPControl_Writer &STEPCAFControl_Writer::ChangeWriter ()
391{
392 return myWriter;
393}
394
395
396//=======================================================================
397//function : Writer
398//purpose :
399//=======================================================================
400
401const STEPControl_Writer &STEPCAFControl_Writer::Writer () const
402{
403 return myWriter;
404}
405
406
407//=======================================================================
408//function : Transfer
409//purpose :
410//=======================================================================
411
412Standard_Boolean STEPCAFControl_Writer::Transfer (STEPControl_Writer &writer,
413 const TDF_LabelSequence &labels,
414 const STEPControl_StepModelType mode,
415 const Standard_CString multi,
416 const Standard_Boolean isExternFile)
417{
418 if ( labels.Length() <=0 ) return Standard_False;
419
420 Handle(STEPCAFControl_ActorWrite) Actor =
421 Handle(STEPCAFControl_ActorWrite)::DownCast ( writer.WS()->NormAdaptor()->ActorWrite() );
422
423 // translate free top-level shapes of the DECAF document
424#ifdef DEB // includes Transfer_ActorOfFinderProcess
425// cout << "Actor is " << writer.WS()->NormAdaptor()->ActorWrite()->DynamicType()->Name() << endl;
426#endif
427 Standard_Integer ap = Interface_Static::IVal ("write.step.schema");
428 TDF_LabelSequence sublabels;
429 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
430 TDF_Label L = labels.Value(i);
431 TopoDS_Shape dummy;
432 if ( myLabels.IsBound ( L ) ) continue; // already processed
433
434 TopoDS_Shape shape = XCAFDoc_ShapeTool::GetShape ( L );
435 if ( shape.IsNull() ) continue;
436
437 // write shape either as a whole, or as multifile (with extern refs)
438 if ( ! multi /* || ! XCAFDoc_ShapeTool::IsAssembly ( L ) */ ) {
439 Actor->SetStdMode ( Standard_False );
440
441 // fill sequence of (sub) shapes for which attributes should be written
442 // and set actor to handle assemblies in a proper way
443 TDF_LabelSequence comp;
444 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_True );
445 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
446 TDF_Label ref;
447 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( comp(k), ref ) ) continue;
448 if ( ! myLabels.IsBound ( ref ) ) {
449 TopoDS_Shape refS = XCAFDoc_ShapeTool::GetShape ( ref );
450 myLabels.Bind ( ref, refS );
451 sublabels.Append ( ref );
452 if ( XCAFDoc_ShapeTool::IsAssembly ( ref ) )
453 Actor->RegisterAssembly ( refS );
454 }
455 }
456 myLabels.Bind ( L, shape );
457 sublabels.Append ( L );
458 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) )
459 Actor->RegisterAssembly ( shape );
460
461 writer.Transfer(shape,mode,Standard_False);
462 Actor->SetStdMode ( Standard_True ); // restore default behaviour
463 }
464 else {
465 // translate final solids
466 TopoDS_Shape Sass = TransferExternFiles ( L, mode, sublabels, multi );
467
468 // translate main assembly structure
469/*
470 if ( ap == 3 ) { // if AP203, switch to AP214
471 Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
472 Handle(StepData_StepModel) model =
473 Handle(StepData_StepModel)::DownCast ( writer.WS()->Model() );
474 if ( model->HasHeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) ) {
475 Handle(HeaderSection_FileSchema) fs =
476 Handle(HeaderSection_FileSchema)::DownCast ( model->HeaderEntity(STANDARD_TYPE(HeaderSection_FileSchema)) );
477 Handle(TCollection_HAsciiString) str = fs->SchemaIdentifiersValue ( 1 );
478 Handle(TCollection_HAsciiString) ap214 = new TCollection_HAsciiString ( "AUTOMOTIVE_DESIGN" );
479 if ( str->Search ( ap214 ) <0 ) {
480 str->Clear();
481 str->AssignCat ( ap214 );
482 }
483 }
484 }
485*/
486 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
487 Interface_Static::SetCVal ("write.step.assembly", "On");
488 writer.Transfer ( Sass, STEPControl_AsIs );
489 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
490 Interface_Static::SetIVal ("write.step.schema", ap);
491 }
492 }
493
494 writer.WS()->ComputeGraph(Standard_True );// added by skl 03.11.2003 since we use
495 // writer.Transfer() wihtout compute graph
496
497 // write names
498 if ( GetNameMode() )
499 WriteNames ( writer.WS(), sublabels );
500
501 if ( !multi ) {
502 // write colors
503 if ( GetColorMode() )
504 WriteColors ( writer.WS(), sublabels );
505
506 // write layers
507 if ( GetLayerMode() )
508 WriteLayers ( writer.WS(), sublabels );
509
510 // write SHUO entities
511 if ( GetSHUOMode() && !isExternFile )
512 // do not store SHUO for extern reference for the moment
513 WriteSHUOs ( writer.WS(), sublabels );
514
515 // write G&DTs
516 if(GetDimTolMode())
517 WriteDGTs(writer.WS(),sublabels);
518
519 // write Materials
520 if(GetMaterialMode())
521 WriteMaterials(writer.WS(),sublabels);
522
523 // register all MDGPRs in model
524 MoniTool_DataMapIteratorOfDataMapOfShapeTransient anItr(myMapCompMDGPR);
525 for (; anItr.More(); anItr.Next()) {
526 Handle(Interface_InterfaceModel) Model = writer.WS()->Model();
527 Model->AddWithRefs( anItr.Value() );
528 }
529 }
530
531 if ( multi ) { // external refs
532 WriteExternRefs ( writer.WS(), sublabels );
533 }
534
535 // write validation props
536// if ( multi && ap ==3 ) {
537// Interface_Static::SetCVal ("write.step.schema", "AP214DIS");
538// }
539 if ( GetPropsMode() )
540 WriteValProps ( writer.WS(), sublabels, multi );
541
542 Interface_Static::SetIVal ("write.step.schema", ap);
543
544 // refresh graph
545 writer.WS()->ComputeGraph ( Standard_True );
546
547 return Standard_True;
548}
549
550
551//=======================================================================
552//function : TransferExternFiles
553//purpose :
554//=======================================================================
555
556TopoDS_Shape STEPCAFControl_Writer::TransferExternFiles (const TDF_Label &L,
557 const STEPControl_StepModelType mode,
558 TDF_LabelSequence &labels,
559 const Standard_CString prefix)
560{
561 // if label already translated, just return the shape
562 if ( myLabels.IsBound ( L ) ) {
563 return myLabels.Find ( L );
564 }
565
566 TopoDS_Compound C;
567 BRep_Builder B;
568 B.MakeCompound ( C );
569 labels.Append ( L );
570
571 // if not assembly, write to separate file
572 if ( ! XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
573
574 // prepare for transfer
575 Handle(XSControl_WorkSession) newWS = new XSControl_WorkSession;
576 newWS->SelectNorm ( "STEP" );
577 STEPControl_Writer sw ( newWS, Standard_True );
578 TDF_LabelSequence Lseq;
579 Lseq.Append ( L );
580
581 // construct the name for extern file
582 Handle(TCollection_HAsciiString) basename = new TCollection_HAsciiString;
583 if ( prefix && prefix[0] ) basename->AssignCat ( prefix );
584 GetLabelName ( L, basename );
585 Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString ( basename );
586 name->AssignCat ( ".stp" );
587 if ( myFiles->HasItem ( name->ToCString() ) ) { // avoid confusions
588 for ( Standard_Integer k=1; k < 32000; k++ ) {
589 name = new TCollection_HAsciiString ( basename );
590 name->AssignCat ( "_" );
591 name->AssignCat ( TCollection_AsciiString ( k ).ToCString() );
592 name->AssignCat ( ".stp" );
593 if ( ! myFiles->HasItem ( name->ToCString() ) ) break;
594 }
595 }
596
597 // translate and record extern file
598 Handle(STEPCAFControl_ExternFile) EF = new STEPCAFControl_ExternFile;
599 EF->SetWS ( newWS );
600 EF->SetName ( name );
601 EF->SetLabel ( L );
602 Standard_Integer assemblymode = Interface_Static::IVal ("write.step.assembly");
603 Interface_Static::SetCVal ("write.step.assembly", "Off");
604 const Standard_CString multi = 0;
605 EF->SetTransferStatus ( Transfer ( sw, Lseq, mode, multi, Standard_True ) );
606 Interface_Static::SetIVal ("write.step.assembly", assemblymode);
607 myLabEF.Bind ( L, EF );
608 myFiles->SetItem ( name->ToCString(), EF );
609
610 // return empty compound as replacement for the shape
611 myLabels.Bind ( L, C );
612 return C;
613 }
614
615 // else iterate on components add create structure of empty compounds
616 // representing the assembly
617 TDF_LabelSequence comp;
618 XCAFDoc_ShapeTool::GetComponents ( L, comp, Standard_False );
619 for ( Standard_Integer k=1; k <= comp.Length(); k++ ) {
620 TDF_Label lab = comp(k);
621 TDF_Label ref;
622 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, ref ) ) continue;
623 TopoDS_Shape Scomp = TransferExternFiles ( ref, mode, labels, prefix );
624 Scomp.Location ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
625 B.Add ( C, Scomp );
626 }
627 myLabels.Bind ( L, C );
628 return C;
629}
630
631
632//=======================================================================
633//function : WriteExternRefs
634//purpose :
635//=======================================================================
636
637Standard_Boolean STEPCAFControl_Writer::WriteExternRefs (const Handle(XSControl_WorkSession) &WS,
638 const TDF_LabelSequence &labels) const
639{
640 if ( labels.Length() <=0 ) return Standard_False;
641
642 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
643 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
644 STEPConstruct_ExternRefs EFTool ( WS );
645 Standard_Integer schema = Interface_Static::IVal("write.step.schema");
646 for ( Standard_Integer k=1; k <= labels.Length(); k++ ) {
647 TDF_Label lab = labels(k);
648 if ( XCAFDoc_ShapeTool::IsAssembly ( lab ) ) continue; // skip assemblies
649
650 // get extern file
651 Handle(STEPCAFControl_ExternFile) EF;
652 if ( ! ExternFile ( lab, EF ) ) continue; // should never be
653
654 // find SDR
655 if ( ! myLabels.IsBound ( lab ) ) continue; // not recorded as translated, skip
656 TopoDS_Shape S = myLabels.Find ( lab );
657
658 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
659 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
660 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
661#ifdef DEB
662 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
663#endif
664 continue;
665 }
666
667 // add extern ref
668 const Standard_CString format = (const Standard_CString) ( schema == 3 ? "STEP AP203" : "STEP AP214" );
669 // try to get PD from SDR
670 StepRepr_RepresentedDefinition RD = SDR->Definition();
671 Handle(StepRepr_PropertyDefinition) aPropDef = RD.PropertyDefinition();
672 if (aPropDef.IsNull()) {
673#ifdef DEB
674 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepRepr_PropertyDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
675#endif
676 continue;
677 }
678 StepRepr_CharacterizedDefinition CharDef = aPropDef->Definition();
679 Handle(StepBasic_ProductDefinition) PD = CharDef.ProductDefinition();
680 if (PD.IsNull()) {
681#ifdef DEB
682 cout << "Warning: STEPCAFControl_Writer::WriteExternRefs StepBasic_ProductDefinition is null for " << S.TShape()->DynamicType()->Name() << endl;
683#endif
684 continue;
685 }
686 EFTool.AddExternRef ( EF->GetName()->ToCString(), PD, format );
687 }
688 EFTool.WriteExternRefs(schema);
689 return Standard_True;
690}
691
692
693//=======================================================================
694//function : FindEntities
695//purpose : auxilary
696//=======================================================================
697static Standard_Integer FindEntities (const Handle(Transfer_FinderProcess) &FP,
698 const TopoDS_Shape &S,
699 TopLoc_Location &L,
700 TColStd_SequenceOfTransient &seqRI)
701{
702 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, S, L );
703
704 if ( ! item.IsNull() ) {
705 seqRI.Append ( item );
706 return 1;
707 }
708
709 // may be S was splited during shape processing
710 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
711 Handle(Transfer_Binder) bnd = FP->Find ( mapper );
712 if ( bnd.IsNull() ) return 0;
713
714 Handle(Transfer_TransientListBinder) TransientListBinder =
715 //Handle(Transfer_TransientListBinder)::DownCast( bnd->Next(Standard_True) );
716 Handle(Transfer_TransientListBinder)::DownCast( bnd );
717 Standard_Integer nres=0;
718 if ( TransientListBinder.IsNull() && S.ShapeType() == TopAbs_COMPOUND)
719 {
720 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
721 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FP, it.Value(), L );
722 if ( item.IsNull() ) continue;
723 nres++;
724 seqRI.Append ( item );
725 }
726 }
727 else
728 {
729 const Standard_Integer nb = TransientListBinder->NbTransients();
730 for (Standard_Integer i=1; i<=nb; i++) {
731 Handle(Standard_Transient) t = TransientListBinder->Transient(i);
732 item = Handle(StepRepr_RepresentationItem)::DownCast(t);
733 if ( item.IsNull() ) continue;
734 nres++;
735 seqRI.Append ( item );
736 }
737 }
738/* works but is obsolete: another approach
739 if (i<=nb) {
740 TopoDS_Shape comp = TransferBRep::ShapeResult(bnd);
741 if ( ! comp.IsNull() && comp.ShapeType() < S.ShapeType() ) {
742 for ( TopoDS_Iterator it(comp); it.More(); it.Next() ) {
743 MakeSTEPStyles(Styles, it.Value(), settings, STEPstyle,
744 Map, ( hasOwn ? &style : 0 ) );
745 }
746 }
747 }
748*/
749 return nres;
750}
751
752
753//=======================================================================
754//function : getStyledItem
755//purpose : auxilary
756//=======================================================================
757static Standard_Boolean getStyledItem(const TopoDS_Shape& S,
758 const Handle(XCAFDoc_ShapeTool)& STool,
759 const STEPConstruct_Styles &Styles,
760 Handle(StepVisual_StyledItem) &resSelItem,
761 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
762{
763 TDF_Label aTopShL = STool->FindShape(S, Standard_False);
764 TopoDS_Shape aTopLevSh = STool->GetShape( aTopShL );
765 Standard_Boolean found = Standard_False;
766 if ( !aTopLevSh.IsNull() && myMapCompMDGPR.IsBound( aTopLevSh ) ) {
767 Handle(StepVisual_PresentationRepresentation) aMDGPR =
768 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopLevSh ) );
769 Handle(StepRepr_HArray1OfRepresentationItem) anSelItmHArr = aMDGPR->Items();
770 // search for PSA of Monifold solid
771 if ( !anSelItmHArr.IsNull() )
772 {
773 for (Standard_Integer si = 1; si <= anSelItmHArr->Length(); si++) {
774 Handle(StepVisual_StyledItem) aSelItm =
775 Handle(StepVisual_StyledItem)::DownCast(anSelItmHArr->Value(si));
776
777 if ( aSelItm.IsNull() )
778 continue;
779
780 // check that it is a stiled item for monifold solid brep
781 TopLoc_Location Loc;
782 TColStd_SequenceOfTransient aNewseqRI;
783 FindEntities ( Styles.FinderProcess(), aTopLevSh, Loc, aNewseqRI );
784 if ( aNewseqRI.Length() > 0 )
785 {
786
787 Handle(StepRepr_RepresentationItem) anItem = aSelItm->Item();
788 Standard_Boolean isSameMonSolBR = Standard_False;
789 for (Standard_Integer mi = 1; mi <= aNewseqRI.Length(); mi++) {
790 if ( !anItem.IsNull() && anItem == aNewseqRI.Value( mi ) ) {
791 isSameMonSolBR = Standard_True;
792 break;
793 }
794 }
795 if (!isSameMonSolBR)
796 continue;
797 }
798
799
800 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
801 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA =
802 Handle(StepVisual_PresentationStyleAssignment)::DownCast(aSelItm->StylesValue(jsi));
803 // check for PSA for top-level (not Presentation style by contex for NAUO)
804 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
805 continue;
806 resSelItem = aSelItm;
807 found = Standard_True;
808 }
809 }
810 }
811 }
812 return found;
813}
814
815
816//=======================================================================
817//function : setDefaultInstanceColor
818//purpose : auxilary
819//=======================================================================
820static Standard_Boolean setDefaultInstanceColor (const Handle(StepVisual_StyledItem) &aSelItm,
821 Handle(StepVisual_PresentationStyleAssignment)& PSA)
822{
823 Standard_Boolean found = Standard_False;
824 for (Standard_Integer jsi = 1; jsi <= aSelItm->NbStyles() && !found; jsi++) {
825 Handle(StepVisual_PresentationStyleAssignment) aFatherPSA =
826 Handle(StepVisual_PresentationStyleAssignment)::DownCast(aSelItm->StylesValue(jsi));
827 // check for PSA for top-level (not Presentation style by contex for NAUO)
828 if (aFatherPSA.IsNull() || aFatherPSA->IsKind(STANDARD_TYPE(StepVisual_PresentationStyleByContext)))
829 return Standard_False;
830
831 // get style select from father PSA
832 if (aFatherPSA->NbStyles() > 0) {
833 Handle(StepVisual_HArray1OfPresentationStyleSelect) aFatherStyles =
834 new StepVisual_HArray1OfPresentationStyleSelect(1, aFatherPSA->NbStyles());
835 for (Standard_Integer k = 1; k <= aFatherPSA->NbStyles(); k++) {
836 StepVisual_PresentationStyleSelect PSS;
837 StepVisual_PresentationStyleSelect olDPSS = aFatherPSA->StylesValue(k);
838 if (!olDPSS.PointStyle().IsNull())
839 PSS.SetValue (olDPSS.PointStyle());
840 else if (!olDPSS.CurveStyle().IsNull())
841 PSS.SetValue (olDPSS.CurveStyle());
842 else if (!olDPSS.SurfaceStyleUsage().IsNull())
843 PSS.SetValue (olDPSS.SurfaceStyleUsage());
844 else {
845 found = Standard_False;
846 break;
847 }
848 //aFatherStyles->SetValue( k, PSS );
849 aFatherStyles->SetValue( k, olDPSS );
850 found = Standard_True;
851 }
852 // init PSA of NAUO
853 if (found) {
854 PSA->Init( aFatherStyles );
855 }
856 }
857
858 }
859 return found;
860}
861
862
863//=======================================================================
864//function : MakeSTEPStyles
865//purpose : auxilary
866//=======================================================================
867static void MakeSTEPStyles (STEPConstruct_Styles &Styles,
868 const TopoDS_Shape &S,
869 const XCAFPrs_DataMapOfShapeStyle &settings,
870 Handle(StepVisual_StyledItem) &override,
871 TopTools_MapOfShape &Map,
872 const MoniTool_DataMapOfShapeTransient& myMapCompMDGPR,
873 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
874 STEPConstruct_DataMapOfPointTransient &ColRGBs,
875 const Handle(XCAFDoc_ColorTool)& CTool,
876 const XCAFPrs_Style *inherit = 0,
877 const Standard_Boolean isComponent = Standard_False)
878{
879 // skip already processed shapes
880 if ( ! Map.Add ( S ) ) return;
881
882 // check if shape has its own style (r inherits from ancestor)
883 XCAFPrs_Style style;
884 if ( inherit ) style = *inherit;
885 if ( settings.IsBound(S) ) {
886 XCAFPrs_Style own = settings.Find(S);
887 if ( !own.IsVisible() ) style.SetVisibility ( Standard_False );
888 if ( own.IsSetColorCurv() ) style.SetColorCurv ( own.GetColorCurv() );
889 if ( own.IsSetColorSurf() ) style.SetColorSurf ( own.GetColorSurf() );
890 }
891
892 // translate colors to STEP
893 Handle(StepVisual_Colour) surfColor, curvColor;
894 if ( style.IsSetColorSurf() )
895 surfColor = Styles.EncodeColor(style.GetColorSurf(),DPDCs,ColRGBs);
896 if ( style.IsSetColorCurv() )
897 curvColor = Styles.EncodeColor(style.GetColorCurv(),DPDCs,ColRGBs);
898
899 Standard_Boolean hasOwn = ( ! surfColor.IsNull() ||
900 ! curvColor.IsNull() ||
901 ! style.IsVisible() );
902
903 // find target item and assign style to it
904 Handle(StepVisual_StyledItem) STEPstyle = override;
905 if ( hasOwn ) {
906 if ( S.ShapeType() != TopAbs_COMPOUND || isComponent ) { // skip compounds, let subshapes inherit its colors
907 TopLoc_Location L;
908 TColStd_SequenceOfTransient seqRI;
909 Standard_Integer nb = FindEntities ( Styles.FinderProcess(), S, L, seqRI );
910#ifdef DEB
911 if ( nb <=0 ) cout << "Warning: Cannot find RI for " << S.TShape()->DynamicType()->Name() << endl;
912#endif
913 //Get overridden style gka 10.06.03
914 if ( isComponent && nb)
915 getStyledItem(S, CTool->ShapeTool(), Styles, override,myMapCompMDGPR);
916
917
918 for ( Standard_Integer i=1; i <= nb; i++ ) {
919 Handle(StepRepr_RepresentationItem) item =
920 Handle(StepRepr_RepresentationItem)::DownCast(seqRI(i));
921 Handle(StepVisual_PresentationStyleAssignment) PSA;
922 if ( style.IsVisible() || !surfColor.IsNull() || !curvColor.IsNull() ) {
923 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
924 }
925 else {
926 // default white color
927 surfColor = Styles.EncodeColor(Quantity_Color(1,1,1,Quantity_TOC_RGB),DPDCs,ColRGBs);
928 PSA = Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
929 if ( isComponent )
930 setDefaultInstanceColor( override, PSA);
931
932 } // end of component case
933
934 STEPstyle = Styles.AddStyle ( item, PSA, override );
935 hasOwn = Standard_False;
936 }
937 }
938 }
939
940 // iterate on subshapes (except vertices :)
941 if ( S.ShapeType() == TopAbs_EDGE ) return;
942 if ( !isComponent ) // PTV 10.02.2003
943 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
944 MakeSTEPStyles ( Styles, it.Value(), settings, STEPstyle,
945 Map, myMapCompMDGPR, DPDCs, ColRGBs, CTool,
946 ( hasOwn ? &style : 0 ) );
947 }
948}
949
950/*
951static Standard_Boolean getFatherColor (const TDF_Label& L,
952 const Handle(XCAFDoc_ColorTool)& CTool,
953 XCAFPrs_Style& style)
954{
955 Standard_Boolean done = Standard_False;
956 TopoDS_Shape aSh = CTool->ShapeTool()->GetShape( L );
957 TDF_Label aFL = CTool->ShapeTool()->FindShape( aSh );
958 if (aFL.IsNull() || aFL == L)
959 return done;
960 Quantity_Color C;
961 if ( CTool->GetColor ( aFL, XCAFDoc_ColorGen, C ) ) {
962 style.SetColorCurv ( C );
963 style.SetColorSurf ( C );
964 done = Standard_True;
965 }
966 if ( CTool->GetColor ( aFL, XCAFDoc_ColorSurf, C ) ) {
967 style.SetColorSurf ( C );
968 done = Standard_True;
969 }
970 if ( CTool->GetColor ( aFL, XCAFDoc_ColorCurv, C ) ) {
971 style.SetColorCurv ( C );
972 done = Standard_True;
973 }
974
975 return done;
976}
977*/
978
979
980//=======================================================================
981//function : WriteColors
982//purpose :
983//=======================================================================
984
985Standard_Boolean STEPCAFControl_Writer::WriteColors (const Handle(XSControl_WorkSession) &WS,
986 const TDF_LabelSequence &labels)
987{
988 if ( labels.Length() <=0 ) return Standard_False;
989
990 // Iterate on shapes in the document
991 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
992 if ( CTool.IsNull() ) return Standard_False;
993
994 STEPConstruct_Styles Styles ( WS );
995 STEPConstruct_DataMapOfAsciiStringTransient DPDCs;
996 STEPConstruct_DataMapOfPointTransient ColRGBs;
997 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
998 TDF_Label L = labels.Value(i);
999
1000 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1001 // Skip assemblies: colors assigned to assemblies and their instances
1002 // are not supported (it is not clear how to encode that in STEP)
1003 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1004#ifdef DEB
1005 cout << "Warning: Cannot write color for Assembly" << endl;
1006 cout << "Info: Check for colors assigned to components in assembly" << endl;
1007#endif
1008 // PTV 22.01.2003 Write color for instances.
1009 TDF_LabelSequence compLabels;
1010 if ( aSTool.IsNull() )
1011 continue;
1012 if (!aSTool->GetComponents(L, compLabels))
1013 continue;
1014 WriteColors(WS, compLabels);
1015 continue;
1016 }
1017 Styles.ClearStyles();
1018
1019 // get a target shape and try to find corresponding context
1020 // (all the colors set under that label will be put into that context)
1021 TopoDS_Shape S;
1022 if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1023 Standard_Boolean isComponent = aSTool->IsComponent( L );
1024 TopoDS_Shape aTopSh = S;
1025 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext ( S );
1026 if ( isComponent ) {
1027 TDF_Label aTopShL = aSTool->FindShape(S, Standard_False);
1028 if (aTopShL.IsNull())
1029 continue;
1030 aTopSh = aSTool->GetShape( aTopShL );
1031 Context = Styles.FindContext ( aTopSh );
1032 }
1033 if ( Context.IsNull() )
1034 continue;
1035
1036 // collect settings set on that label
1037 XCAFPrs_DataMapOfShapeStyle settings;
1038 TDF_LabelSequence seq;
1039 seq.Append ( L );
1040 XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
1041 Standard_Boolean isVisible = Standard_True;
1042 for ( Standard_Integer j = 1; j <= seq.Length(); j++ ) {
1043 TDF_Label lab = seq.Value(j);
1044 XCAFPrs_Style style;
1045 Quantity_Color C;
1046 if ( isComponent && lab == L ) {
1047 // check for invisible status of object on label
1048 if ( !CTool->IsVisible( lab ) ) {
1049 isVisible = Standard_False;
1050 style.SetVisibility( Standard_False );
1051 }
1052 }
1053 if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
ec99ba32
G
1054 style.SetColorCurv ( C );
1055 style.SetColorSurf ( C );
7fd59977 1056 }
1057 if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
ec99ba32 1058 style.SetColorSurf ( C );
7fd59977 1059 if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
ec99ba32
G
1060 style.SetColorCurv ( C );
1061
7fd59977 1062 // commented, cause we are need to take reference from
1063// if ( isComponent && lab == L && !isVisible)
1064// if ( !style.IsSetColorSurf() && !style.IsSetColorCurv() ) {
1065// getFatherColor ( L, CTool, style);
1066// }
1067 if ( ! style.IsSetColorCurv() && ! style.IsSetColorSurf() && isVisible ) continue;
1068
1069 TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
1070 settings.Bind ( sub, style );
1071 }
1072
1073 if ( settings.Extent() <=0 ) continue;
1074
1075 // iterate on subshapes and create STEP styles
1076 Handle(StepVisual_StyledItem) override;
1077 TopTools_MapOfShape Map;
1078
1079 MakeSTEPStyles(Styles,S,settings,override,Map,myMapCompMDGPR,DPDCs,ColRGBs,CTool,0,isComponent);
1080
1081 // create MDGPR and record it in model
1082 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1083
1084 if (!isComponent) {
1085 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1086#ifdef DEB
1087 cerr << "Error: Current Top-Level shape have MDGPR already " << endl;
1088#endif
1089 }
1090 Styles.CreateMDGPR ( Context, aMDGPR );
1091 if (!aMDGPR.IsNull())
1092 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1093 }
1094 else {
1095 // create SDR and add to model.
1096 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1097 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1098 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1099 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1100 if ( FP->FindTypedTransient(mapper,
1101 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1102 CDSR) ) {
1103 // create SDR for NAUO
1104 Handle(StepRepr_ProductDefinitionShape) nullPDS; // important to be NULL
1105 Styles.CreateNAUOSRD( Context, CDSR, nullPDS );
1106
1107 // search for MDGPR of the component top-level shape
1108 if ( myMapCompMDGPR.IsBound( aTopSh )) {
1109 aMDGPR = Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1110 } else {
1111 aMDGPR = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
1112 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
1113 aMDGPR->SetName( ReprName );
1114 aMDGPR->SetContextOfItems( Context );
1115 myMapCompMDGPR.Bind ( aTopSh, aMDGPR );
1116 }
1117 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1118 Standard_Integer oldLengthlen = 0;
1119 if (!oldItems.IsNull())
1120 oldLengthlen = oldItems->Length();
1121 const Standard_Integer nbIt = oldLengthlen + Styles.NbStyles();
1122 if(!nbIt)
1123 continue;
1124 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1125 new StepRepr_HArray1OfRepresentationItem(1, nbIt);
1126 Standard_Integer si;
1127 Standard_Integer el = 1;
1128 for ( si=1; si <= oldLengthlen; si++ )
1129 newItems->SetValue( el++, oldItems->Value( si ) );
1130 for ( si=1; si <= Styles.NbStyles(); si++ ) {
1131 newItems->SetValue( el++, Handle(StepRepr_RepresentationItem)::DownCast(Styles.Style(si)));
1132// WP->Model()->AddWithRefs ( Handle(StepRepr_RepresentationItem)::DownCast (Styles.Style(si)));
1133 }
1134 if ( !isVisible ) {
1135 // create invisibility item and refer for stiledItem
1136 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1137 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1138 new StepVisual_HArray1OfInvisibleItem (1,Styles.NbStyles());
1139 // put all style item into the harray
1140 for ( si=1; si <= Styles.NbStyles(); si++ ) {
1141 Handle(StepRepr_RepresentationItem) styledItm =
1142 Handle(StepRepr_RepresentationItem)::DownCast(Styles.Style(si));
1143 StepVisual_InvisibleItem anInvItem;
1144 anInvItem.SetValue( styledItm );
1145 HInvsblItm->SetValue( si, anInvItem );
1146 }
1147 // set the invisibility of items
1148 Invsblt->Init( HInvsblItm );
1149 WS->Model()->AddWithRefs( Invsblt );
1150 }
1151
1152 if (newItems->Length() > 0)
1153 aMDGPR->SetItems( newItems );
1154 } //end of work with CDSR
1155 }
1156 }
1157
1158 return Standard_True;
1159}
1160
1161
1162//=======================================================================
1163//function : WriteNames
1164//purpose :
1165//=======================================================================
1166
1167Standard_Boolean STEPCAFControl_Writer::WriteNames (const Handle(XSControl_WorkSession) &WS,
1168 const TDF_LabelSequence &labels) const
1169{
1170 if ( labels.Length() <=0 ) return Standard_False;
1171
1172 // get working data
1173 Handle(Interface_InterfaceModel) Model = WS->Model();
1174 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1175 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1176// Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1177// if ( STool.IsNull() ) return Standard_False;
1178
1179 // Iterate on requested shapes
1180 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1181 TDF_Label L = labels.Value(i);
1182
1183 // get name
1184 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1185 if ( ! GetLabelName (L, hName) ) continue;
1186// Handle(TDataStd_Name) N;
1187// if ( ! L.FindAttribute ( TDataStd_Name::GetID(), N ) ) continue;
1188// TCollection_ExtendedString name = N->Get();
1189// if ( name.Length() <=0 ) continue;
1190
1191 // find target STEP entity for the current shape
1192// TopoDS_Shape S;
1193// if ( ! XCAFDoc_ShapeTool::GetShape ( L, S ) ) continue;
1194 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1195 TopoDS_Shape S = myLabels.Find ( L );
1196
1197 Handle(StepShape_ShapeDefinitionRepresentation) SDR;
1198 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
1199 if ( ! FP->FindTypedTransient ( mapper, STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation), SDR ) ) {
1200#ifdef DEB
1201 cout << "Warning: Cannot find SDR for " << S.TShape()->DynamicType()->Name() << endl;
1202#endif
1203 continue;
1204 }
1205
1206 // set the name to the PRODUCT
1207 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1208 if ( PropD.IsNull() ) continue;
1209 Handle(StepBasic_ProductDefinition) PD = PropD->Definition().ProductDefinition();
1210 if ( PD.IsNull() ) continue;
1211 Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
1212
1213 Prod->SetId ( hName );
1214 Prod->SetName ( hName );
1215
1216 // write names for components of assemblies
1217 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1218 TDF_LabelSequence seq;
1219 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1220 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1221 TDF_Label lab = seq(k);
1222
1223 // get shape with correct location
1224 TDF_Label Lref;
1225 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1226 ! myLabels.IsBound ( Lref ) ) continue;
1227 S = myLabels.Find ( Lref );
1228 S.Move ( XCAFDoc_ShapeTool::GetLocation ( lab ) );
1229
1230 hName = new TCollection_HAsciiString;
1231 if ( ! GetLabelName (lab, hName) ) continue;
1232
1233 // find the target CDSR corresponding to a shape
1234 mapper = TransferBRep::ShapeMapper ( FP, S );
1235 Handle(Transfer_Binder) binder = FP->Find ( mapper );
1236 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1237 if ( ! FP->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation), CDSR) )
1238 continue;
1239 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1240 Handle(StepBasic_ProductDefinitionRelationship) NAUO = PDS->Definition().ProductDefinitionRelationship();
1241 if ( ! NAUO.IsNull() ) NAUO->SetName ( hName );
1242 }
1243 }
1244 }
1245
1246 return Standard_True;
1247}
1248
1249
1250//=======================================================================
1251//function : WritePropsForLabel
1252//purpose :
1253//=======================================================================
1254static Standard_Boolean WritePropsForLabel(const Handle(XSControl_WorkSession) &WS,
1255 const Handle(XCAFDoc_ShapeTool) &aSTool,
1256 const STEPCAFControl_DataMapOfLabelShape &myLabels,
1257 const TDF_Label &L,
1258 const Standard_CString multi)
1259{
1260 if(L.IsNull()) return Standard_False;
1261
1262 STEPConstruct_ValidationProps Props ( WS );
1263
1264 TopoDS_Shape S = aSTool->GetShape(L);
1265 if(S.IsNull()) return Standard_False;
1266
1267 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1268 // write area
1269 Handle(XCAFDoc_Area) A;
1270 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1271 if ( ! A.IsNull() ) {
1272 Props.AddArea ( S, A->Get() );
1273 }
1274 // write volume
1275 Handle(XCAFDoc_Volume) V;
1276 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1277 if ( ! V.IsNull() ) {
1278 Props.AddVolume ( S, V->Get() );
1279 }
1280 }
1281 // write centroid
1282 Handle(XCAFDoc_Centroid) C;
1283 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1284 if ( ! C.IsNull() ) {
1285 Props.AddCentroid ( S, C->Get() );
1286 }
1287
1288 if( XCAFDoc_ShapeTool::IsCompound(L) || XCAFDoc_ShapeTool::IsAssembly(L) ) {
1289 if(L.HasChild()) {
1290 for(Standard_Integer ich=1; ich<=L.NbChildren(); ich++) {
1291 WritePropsForLabel(WS,aSTool,myLabels,L.FindChild(ich),multi);
1292 }
1293 }
1294 }
1295
1296 return Standard_True;
1297}
1298
1299
1300//=======================================================================
1301//function : WriteValProps
1302//purpose :
1303//=======================================================================
1304
1305Standard_Boolean STEPCAFControl_Writer::WriteValProps (const Handle(XSControl_WorkSession) &WS,
1306 const TDF_LabelSequence &labels,
1307 const Standard_CString multi) const
1308{
1309 if ( labels.Length() <=0 ) return Standard_False;
1310
1311 // get working data
1312// STEPConstruct_ValidationProps Props ( WS );
1313 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
1314
1315 // Iterate on requested shapes
1316 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1317 TDF_Label L = labels.Value(i);
1318
1319 WritePropsForLabel(WS,aSTool,myLabels,L,multi);
1320/*
1321 // find target STEP entity for the current shape
1322 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1323 TopoDS_Shape S = myLabels.Find ( L );
1324
1325 // write area and volume (except for components in multifile mode)
1326 if ( ! multi || XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1327 Handle(XCAFDoc_Area) A;
1328 L.FindAttribute ( XCAFDoc_Area::GetID(), A );
1329 if ( ! A.IsNull() ) Props.AddArea ( S, A->Get() );
1330
1331 Handle(XCAFDoc_Volume) V;
1332 L.FindAttribute ( XCAFDoc_Volume::GetID(), V );
1333 if ( ! V.IsNull() ) Props.AddVolume ( S, V->Get() );
1334 }
1335
1336 // write centroid
1337 Handle(XCAFDoc_Centroid) C;
1338 L.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1339 if ( ! C.IsNull() ) Props.AddCentroid ( S, C->Get() );
1340
1341 // write centroid for components of assemblies
1342 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1343 TDF_LabelSequence seq;
1344 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1345 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1346 TDF_Label lab = seq(k);
1347
1348 // get shape with correct location
1349 TDF_Label Lref;
1350 if ( ! XCAFDoc_ShapeTool::GetReferredShape ( lab, Lref ) ||
1351 ! myLabels.IsBound ( Lref ) ) continue;
1352 TopLoc_Location Loc = XCAFDoc_ShapeTool::GetLocation ( lab );
1353 S = myLabels.Find ( Lref );
1354 S.Move ( Loc );
1355
1356 C.Nullify();
1357 lab.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1358 // if centroid is not assigned to an instance,
1359 // use (shifted) centroid of original shape
1360 gp_Pnt center;
1361 if ( C.IsNull() ) {
1362 Lref.FindAttribute ( XCAFDoc_Centroid::GetID(), C );
1363 if ( C.IsNull() ) continue;
1364 center = C->Get().Transformed ( Loc.Transformation() );
1365 }
1366 else center = C->Get();
1367
1368 Props.AddCentroid ( S, center, Standard_True );
1369 }
1370 }
1371*/
1372 }
1373
1374 return Standard_True;
1375}
1376
1377
1378//=======================================================================
1379//function : WriteLayers
1380//purpose :
1381//=======================================================================
1382
1383Standard_Boolean STEPCAFControl_Writer::WriteLayers (const Handle(XSControl_WorkSession) &WS,
1384 const TDF_LabelSequence &labels ) const
1385{
1386
1387 if ( labels.Length() <=0 ) return Standard_False;
1388
1389 // get working data
1390 Handle(Interface_InterfaceModel) Model = WS->Model();
1391 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1392 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1393 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( labels(1) );
1394 if (LTool.IsNull() ) return Standard_False;
1395
1396 TDF_LabelSequence LayerLS;
1397 LTool->GetLayerLabels(LayerLS);
1398 if ( LayerLS.Length() <=0 ) return Standard_False;
1399
1400 // Iterate on requested layers and for each layer take set of shapes.
1401 for ( Standard_Integer i=1; i <= LayerLS.Length(); i++ ) {
1402 TDF_Label L = LayerLS.Value(i);
1403
1404 // get labels of shapes in that layer
1405 TDF_LabelSequence ShapeLs;
1406 LTool->GetShapesOfLayer(L, ShapeLs);
1407 if ( ShapeLs.Length() <=0 ) continue;
1408
1409 // name of layer: if not set, is considered as being empty
1410 Handle(TCollection_HAsciiString) hName = new TCollection_HAsciiString;
1411 GetLabelName ( L, hName );
1412
1413 // Find target STEP entity for each shape and add to StepVisual_PresentationLayerAssignment items.
1414 TColStd_SequenceOfTransient seqRI;
1415 for ( Standard_Integer j=1; j <= ShapeLs.Length(); j++) {
1416 TDF_Label shLabel = ShapeLs.Value(j);
1417 if ( shLabel.IsNull() ) continue;
1418
1419 // there is no way to assign layer to instance in STEP
1420 if ( XCAFDoc_ShapeTool::IsAssembly ( shLabel ) ||
1421 XCAFDoc_ShapeTool::IsReference ( shLabel ) )
1422 continue;
1423
1424 // check that the shape is one of (uub)labels written during current transfer
1425 Standard_Integer k = 1;
1426 for ( ; k <= labels.Length(); k++ )
1427 if ( shLabel.IsDescendant ( labels(k) ) ) break;
1428 if ( k > labels.Length() ) continue;
1429
1430 // get target STEP entity
1431 TopoDS_Shape oneShape = XCAFDoc_ShapeTool::GetShape(shLabel);
1432
1433 TopLoc_Location Loc;
1434 Standard_Integer nb =
1435 FindEntities ( FP, oneShape, Loc, seqRI );
1436 if ( nb <=0 )
1437 FP->Messenger() << "Warning: Cannot find RI for " << oneShape.TShape()->DynamicType()->Name() << endl;
1438 }
1439 if ( seqRI.Length() <= 0 ) continue;
1440
1441 // analyze visibility
1442 Handle(StepVisual_PresentationLayerAssignment) StepLayerAs = new StepVisual_PresentationLayerAssignment;
1443 Handle(TCollection_HAsciiString) descr;
1444 Handle(TDataStd_UAttribute) aUAttr;
1445 Standard_Boolean isLinv = Standard_False;
1446 if (L.FindAttribute(XCAFDoc::InvisibleGUID(), aUAttr)) {
1447 descr = new TCollection_HAsciiString ("invisible");
1448#ifdef DEB
1449 FP->Messenger() << "\tLayer \"" << hName->String().ToCString() << "\" is invisible"<<endl;
1450#endif
1451 isLinv = Standard_True;
1452 }
1453 else descr = new TCollection_HAsciiString ("visible");
1454
1455 // create layer entity
1456 Handle(StepVisual_HArray1OfLayeredItem) HArrayOfLItem =
1457 new StepVisual_HArray1OfLayeredItem ( 1, seqRI.Length() );
1458 for (Standard_Integer i1 = 1; i1<=seqRI.Length(); i1++) {
1459 StepVisual_LayeredItem LI;
1460 LI.SetValue ( seqRI.Value(i1) );
1461 HArrayOfLItem->SetValue( i1, LI );
1462 }
1463 StepLayerAs->Init(hName, descr, HArrayOfLItem);
1464 Model->AddWithRefs( StepLayerAs );
1465 // PTV 23.01.2003 add the invisibility AFTER adding layer into the model.
1466 // add the invisibility for the layer
1467 if (isLinv) {
1468 // Invisibility Item for containig invisible layers.
1469 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm = new StepVisual_HArray1OfInvisibleItem (1,1);
1470 StepVisual_InvisibleItem InvIt;
1471 InvIt.SetValue( StepLayerAs );
1472 HInvsblItm->SetValue( 1, InvIt);
1473
1474 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1475 Invsblt->Init( HInvsblItm );
1476 Model->AddWithRefs( Invsblt );
1477 }
1478 }
1479 return Standard_True;
1480}
1481
1482
1483//=======================================================================
1484//function : getSHUOstyle
1485//purpose : auxilary
1486//=======================================================================
1487static Standard_Boolean getSHUOstyle(const TDF_Label& aSHUOlab,
1488 const Handle(XCAFDoc_ColorTool)& CTool,
1489 XCAFPrs_Style& SHUOstyle)
1490{
1491 Quantity_Color C;
1492 if (!CTool->IsVisible( aSHUOlab ) )
1493 SHUOstyle.SetVisibility(Standard_False);
1494 else {
1495 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
1496 SHUOstyle.SetColorCurv ( C );
1497 SHUOstyle.SetColorSurf ( C );
1498 }
1499 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
1500 SHUOstyle.SetColorSurf ( C );
1501 if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
1502 SHUOstyle.SetColorCurv ( C );
1503 }
1504 if ( !SHUOstyle.IsSetColorCurv() &&
1505 !SHUOstyle.IsSetColorSurf() &&
1506 SHUOstyle.IsVisible() )
1507 return Standard_False;
1508 return Standard_True;
1509}
1510
1511
1512//=======================================================================
1513//function : getProDefinitionOfNAUO
1514//purpose : auxilary
1515//=======================================================================
1516static Standard_Boolean getProDefinitionOfNAUO(const Handle(XSControl_WorkSession)& WS,
1517 const TopoDS_Shape& theShape,
1518 Handle(StepBasic_ProductDefinition)& PD,
1519 Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO,
1520 Standard_Boolean IsRelating)
1521{
1522 if ( theShape.IsNull() )
1523 return Standard_False;
1524 // get CDSR
1525 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1526 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1527 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1528 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, theShape );
1529 if (!FP->FindTypedTransient(mapper,
1530 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1531 CDSR))
1532 return Standard_False;
1533 // get PDS of NAUO
1534 Handle(StepRepr_ProductDefinitionShape) PDS = CDSR->RepresentedProductRelation();
1535 if (PDS.IsNull())
1536 return Standard_False;
1537 // get the NAUO entity
1538 Interface_Graph aGraph = WS->HGraph()->Graph();
1539 Interface_EntityIterator subs = aGraph.Shareds(PDS);
1540 for ( subs.Start(); subs.More(); subs.Next() ) {
1541 if (!subs.Value()->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence)))
1542 continue;
1543 NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(subs.Value());
1544 break;
1545 }
1546 if ( NAUO.IsNull() )
1547 return Standard_False;
1548 // get Relatinf or Related product definition
1549 if ( !IsRelating )
1550 PD = NAUO->RelatedProductDefinition();
1551 else
1552 PD = NAUO->RelatingProductDefinition();
1553 if ( PD.IsNull() )
1554 return Standard_False;
1555 return Standard_True;
1556}
1557
1558
1559//=======================================================================
1560//function : writeSHUO
1561//purpose : auxilary
1562//=======================================================================
1563static Standard_Boolean writeSHUO (const Handle(XCAFDoc_GraphNode)& theSHUO,
1564 const Handle(XCAFDoc_ShapeTool)& theSTool,
1565 const Handle(XSControl_WorkSession)& WS,
1566 Handle(StepRepr_SpecifiedHigherUsageOccurrence)& theTopSHUO,
1567 TopoDS_Shape& NAUOShape,
1568 Handle(StepBasic_ProductDefinition)& theRelatingPD,
1569 Standard_Boolean& isDeepest)
1570{
1571 // set the ProductDefinitionRelationship descriptin information as empty strings.
1572 Handle(TCollection_HAsciiString) EmptyString = new TCollection_HAsciiString("");
1573
1574 TDF_LabelSequence aNextUsageLabs;
1575 theSTool->GetSHUONextUsage( theSHUO->Label(), aNextUsageLabs );
1576 Handle(XCAFDoc_GraphNode) NuSHUO;
1577 if ( theTopSHUO.IsNull() ) {
1578 // the top SHUO
1579 if (aNextUsageLabs.Length() < 1)
1580 return Standard_False;
1581 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1582 if (NuSHUO.IsNull())
1583 return Standard_False;
1584 // get relating product definition
1585 TopoDS_Shape aTopCompShape = theSTool->GetShape( theSHUO->Label().Father() );
1586 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO;
1587 if (!getProDefinitionOfNAUO( WS, aTopCompShape,
1588 theRelatingPD, UUNAUO, Standard_True ))
1589 return Standard_False;
1590 // get related product definition
1591 TopoDS_Shape aNUShape = theSTool->GetShape( NuSHUO->Label().Father() );
1592 Handle(StepBasic_ProductDefinition) aRelatedPD;
1593 Handle(StepRepr_NextAssemblyUsageOccurrence) NUNAUO;
1594 if (!getProDefinitionOfNAUO( WS, aNUShape,
1595 aRelatedPD, NUNAUO, Standard_False ))
1596 return Standard_False;
1597
1598 theTopSHUO = new StepRepr_SpecifiedHigherUsageOccurrence;
1599 // create deepest shuo EmptyString
1600 theTopSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1601 /*no description*/Standard_False,/*description*/EmptyString,
1602 theRelatingPD, aRelatedPD,
1603 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1604 /*upper_usage*/UUNAUO, /*next_usage*/NUNAUO);
1605 // write the other SHUO.
1606 if(!writeSHUO( NuSHUO, theSTool, WS, theTopSHUO, NAUOShape, theRelatingPD, isDeepest )) {
1607 theTopSHUO.Nullify();
1608 return Standard_False;
1609 }
1610
1611 return Standard_True;
1612 }
1613// Handle(XCAFDoc_GraphNode) NuSHUO;
1614 if ( aNextUsageLabs.Length() > 0) {
1615 // store SHUO recursive
1616#ifdef DEB
1617 if ( aNextUsageLabs.Length() > 1 )
1618 cout << "Warning: store only one next_usage of current SHUO" << endl;
1619#endif
1620 theSTool->GetSHUO( aNextUsageLabs.Value(1), NuSHUO );
1621 Handle(StepRepr_SpecifiedHigherUsageOccurrence) aNUEntSHUO =
1622 new StepRepr_SpecifiedHigherUsageOccurrence;
1623 if (!writeSHUO( NuSHUO, theSTool, WS, aNUEntSHUO, NAUOShape, theRelatingPD, isDeepest ))
1624 return Standard_False;
1625
1626 // store the deepest SHUO to the dociment
1627 TopoDS_Shape aNUSh, aUUSh;
1628 aNUSh = theSTool->GetShape( NuSHUO->Label().Father() );
1629 aUUSh = theSTool->GetShape( theSHUO->Label().Father() );
1630 // get relating PD with upper_usage and related PD with next_usage
1631 Handle(StepBasic_ProductDefinition) nullPD;// no need to use,case have shared <theRelatingPD>
1632 Handle(StepBasic_ProductDefinition) aRelatedPD;
1633 Handle(StepRepr_NextAssemblyUsageOccurrence) UUNAUO, NUNAUO;
1634 if (!getProDefinitionOfNAUO( WS, aUUSh, nullPD, UUNAUO, Standard_True ) ||
1635 !getProDefinitionOfNAUO( WS, aNUSh, aRelatedPD, NUNAUO, Standard_False )) {
1636#ifdef DEB
1637 cout << "Warning: cannot get related or relating PD" << endl;
1638#endif
1639 return Standard_False;
1640 }
1641 aNUEntSHUO->Init(/*id*/EmptyString, /*name*/EmptyString,
1642 /*no description*/Standard_False,/*description*/EmptyString,
1643 theRelatingPD, aRelatedPD,
1644 /*no ACURefDesignator*/Standard_False,/*ACURefDesignator*/EmptyString,
1645 /*upper_usage*/theTopSHUO, /*next_usage*/NUNAUO);
1646 if ( isDeepest ) {
1647 isDeepest = Standard_False;
1648 }
1649 WS->Model()->AddWithRefs ( aNUEntSHUO );
1650 return Standard_True;
1651 } // end of recurse storing
1652
1653 // get shape
1654 TDF_Label aShapeL = theSHUO->Label().Father();
1655 NAUOShape = theSTool->GetShape( aShapeL );
1656 // return to the deepest level from SHUO shape level
1657 // it is because SHUO is attribute on deep level and shape level.
1658 isDeepest = Standard_True;
1659 return Standard_True;
1660}
1661
1662
1663//=======================================================================
1664//function : createSHUOStyledItem
1665//purpose : auxilary
1666//=======================================================================
1667static Standard_Boolean createSHUOStyledItem (const XCAFPrs_Style& style,
1668 const Handle(StepRepr_ProductDefinitionShape)& PDS,
1669 const Handle(XSControl_WorkSession) &WS,
1670 const TopoDS_Shape& Sh,
1671 const Handle(XCAFDoc_ShapeTool)& STool,
1672 MoniTool_DataMapOfShapeTransient& myMapCompMDGPR)
1673{
1674 // create styled item for the indicated SHUO and store to the model
1675 STEPConstruct_Styles Styles( WS );
1676 // translate colors to STEP
1677 Handle(StepVisual_Colour) surfColor, curvColor;
1678 if ( style.IsSetColorSurf() )
1679 surfColor = Styles.EncodeColor ( style.GetColorSurf() );
1680 if ( style.IsSetColorCurv() )
1681 curvColor = Styles.EncodeColor ( style.GetColorCurv() );
1682 Standard_Boolean isComponent = Standard_True;// cause need to get PSBC
1683 Handle(StepRepr_RepresentationItem) item;
1684 // set default color for invisible SHUO.
1685 Standard_Boolean isSetDefaultColor = Standard_False;
1686 if (surfColor.IsNull() && curvColor.IsNull() && !style.IsVisible() ) {
1687 surfColor = Styles.EncodeColor ( Quantity_Color( 1, 1, 1, Quantity_TOC_RGB ) );
1688 isSetDefaultColor = Standard_True;
1689 }
1690 Handle(StepVisual_PresentationStyleAssignment) PSA =
1691 Styles.MakeColorPSA ( item, surfColor, curvColor, isComponent );
1692 Handle(StepVisual_StyledItem) override; //null styled item
1693
1694 // find the repr item of the shape
1695 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1696 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1697 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, Sh );
1698 Handle(StepShape_ContextDependentShapeRepresentation) CDSR;
1699 FP->FindTypedTransient(mapper,
1700 STANDARD_TYPE(StepShape_ContextDependentShapeRepresentation),
1701 CDSR);
1702 if ( CDSR.IsNull() )
1703 return Standard_False;
1704 // find context
1705 Handle(StepRepr_RepresentationContext) Context = Styles.FindContext( Sh );
1706 TopoDS_Shape aTopSh = Sh;
1707 if (Context.IsNull()) {
1708 TDF_Label aTopShL = STool->FindShape(Sh, Standard_False);
1709 if (aTopShL.IsNull())
1710 return Standard_False;
1711 aTopSh = STool->GetShape( aTopShL );
1712 Context = Styles.FindContext ( aTopSh );
1713 }
1714 if (Context.IsNull())
1715 return Standard_False;
1716 // get representation item of the shape
1717 TopLoc_Location L;
1718 TColStd_SequenceOfTransient seqRI;
1719 FindEntities ( FP, Sh, L, seqRI );
1720#ifdef DEB
1721 if ( seqRI.Length() <=0 )
1722 FP->Messenger() << "Warning: Cannot find RI for " << Sh.TShape()->DynamicType()->Name() << endl;
1723#endif
1724 item = Handle(StepRepr_RepresentationItem)::DownCast(seqRI(1));
1725 //get overridden styled item
1726 getStyledItem(Sh,STool, Styles, override,myMapCompMDGPR);
1727
1728 // get STEP STYLED ITEM
1729 Handle(StepVisual_StyledItem) STEPstyle = Styles.AddStyle ( item, PSA, override );
1730 // create SR, SDR and all necessary references between them and ST, PDS, PSBC, GRC
1731 Styles.CreateNAUOSRD( Context, CDSR, PDS );
1732
1733 // add step styled item of SHUO to the model
1734 // do it by additing styled item to the MDGPR
1735 if ( !aTopSh.IsNull() && !myMapCompMDGPR.IsBound( aTopSh ) ) {
1736 // create MDGPR and record it in model
1737#ifdef DEB
1738 cout << "Warning: " << __FILE__ << ": Create new MDGPR for SHUO instance" << endl;
1739#endif
1740 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation) aMDGPR;
1741 Styles.CreateMDGPR ( Context, aMDGPR );
1742 if (!aMDGPR.IsNull())
1743 myMapCompMDGPR.Bind( aTopSh, aMDGPR );
1744 }
1745 else if ( !aTopSh.IsNull() && myMapCompMDGPR.IsBound( aTopSh ) ) {
1746 // get MDGPR of the top-level shape
1747 Handle(StepVisual_PresentationRepresentation) aMDGPR =
1748 Handle(StepVisual_PresentationRepresentation)::DownCast( myMapCompMDGPR.Find( aTopSh ) );
1749 // get old styled items to not lose it
1750 Handle(StepRepr_HArray1OfRepresentationItem) oldItems = aMDGPR->Items();
1751 Standard_Integer oldLengthlen = 0;
1752 if (!oldItems.IsNull())
1753 oldLengthlen = oldItems->Length();
1754 // create new array of styled items by an olds and new one
1755 Handle(StepRepr_HArray1OfRepresentationItem) newItems =
1756 new StepRepr_HArray1OfRepresentationItem(1, oldLengthlen + 1);
1757 Standard_Integer si;
1758 Standard_Integer el = 1;
1759 for ( si=1; si <= oldLengthlen; si++ )
1760 newItems->SetValue( el++, oldItems->Value( si ) );
1761 newItems->SetValue( el++, Handle(StepRepr_RepresentationItem)::DownCast(STEPstyle) );
1762 // init MDGPR be new array of styled items
1763 if (newItems->Length() > 0)
1764 aMDGPR->SetItems( newItems );
1765 }
1766 else {
1767 WS->Model()->AddWithRefs ( STEPstyle ); // add as root to the model, but it is not good
1768#ifdef DEB
1769 cout << "Warning: " << __FILE__ << ": adds styled item of SHUO as root, casue cannot find MDGPR" << endl;
1770#endif
1771 }
1772 // create invisibility item for the styled item
1773 if ( !style.IsVisible() ) {
1774 if (isSetDefaultColor) {
1775 // try to set default color from top-level shape
1776
1777 setDefaultInstanceColor(override, PSA);
1778 }
1779 // create invisibility item and refer for stiledItem
1780 Handle(StepVisual_Invisibility) Invsblt = new StepVisual_Invisibility();
1781 Handle(StepVisual_HArray1OfInvisibleItem) HInvsblItm =
1782 new StepVisual_HArray1OfInvisibleItem (1,1);
1783 // put all style item into the harray
1784 StepVisual_InvisibleItem anInvItem;
1785 anInvItem.SetValue( STEPstyle );
1786 HInvsblItm->SetValue( 1, anInvItem );
1787 Invsblt->Init( HInvsblItm );
1788 WS->Model()->AddWithRefs( Invsblt );
1789 }
1790
1791 return Standard_True;
1792}
1793
1794
1795//=======================================================================
1796//function : WriteSHUOs
1797//purpose :
1798//=======================================================================
1799
1800Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkSession) &WS,
1801 const TDF_LabelSequence &labels )
1802{
1803 if ( labels.Length() <=0 ) return Standard_False;
1804
1805 // get working data
1806 Handle(Interface_InterfaceModel) Model = WS->Model();
1807 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1808 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1809 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( labels(1) );
1810 if (CTool.IsNull() )
1811 return Standard_False;
1812 // map of transfered SHUO
1813 TColStd_MapOfTransient aMapOfMainSHUO;
1814// TColStd_IndexedDataMapOfTransientTransient aIndxMapOfSHUOEnt;
1815 // Iterate on requested shapes
1816 for ( Standard_Integer i=1; i <= labels.Length(); i++ ) {
1817 TDF_Label L = labels.Value(i);
1818 if ( ! myLabels.IsBound ( L ) ) continue; // not recorded as translated, skip
1819// TopoDS_Shape S = myLabels.Find ( L );
1820 if ( XCAFDoc_ShapeTool::IsAssembly ( L ) ) {
1821 TDF_LabelSequence seq;
1822 XCAFDoc_ShapeTool::GetComponents ( L, seq );
1823 // iterates on components of assembly
1824 for (Standard_Integer k=1; k <= seq.Length(); k++) {
1825 TDF_Label lab = seq(k);
1826 TDF_AttributeSequence anAttrSeq;
1827 CTool->ShapeTool()->GetAllComponentSHUO( lab, anAttrSeq );
1828 // work with SHUO
1829 for (Standard_Integer j = 1; j <= anAttrSeq.Length(); j++) {
1830 Handle(XCAFDoc_GraphNode) aSHUO =
1831 Handle(XCAFDoc_GraphNode)::DownCast(anAttrSeq.Value( j ));
1832 // take label of SHUO
1833 TDF_Label aSHUOlab = aSHUO->Label();
1834 TDF_LabelSequence aUpLabels;
1835 // check is it SHUO of upper_usage
1836 CTool->ShapeTool()->GetSHUOUpperUsage( aSHUOlab, aUpLabels );
1837 if ( aUpLabels.Length() > 0 )
1838 continue; // transfer only main SHUO
1839 if ( aMapOfMainSHUO.Contains( aSHUO ) )
1840 continue; // do not try to transfer SHUO twice
1841 aMapOfMainSHUO.Add( aSHUO );
1842 // check if it is styled SHUO
1843 XCAFPrs_Style SHUOstyle;
1844 if ( !getSHUOstyle ( aSHUOlab, CTool, SHUOstyle ) ) {
1845#ifdef DEB
1846 cout << "Warning: " << __FILE__ << ": do not store SHUO without any style to the STEP model" << endl;
1847#endif
1848 continue;
1849 }
1850 // write SHUO to the model amd then add structure type.
1851 TopoDS_Shape NAUOShape; // shape of the deepest NAUO in the SHUO structure
1852 Standard_Boolean isDeepest = Standard_False;
1853 Handle(StepRepr_SpecifiedHigherUsageOccurrence) anEntOfSHUO;
1854 Handle(StepBasic_ProductDefinition) aRelatingPD;
1855 // create the top SHUO and all other.
1856 writeSHUO( aSHUO, CTool->ShapeTool(), WS, anEntOfSHUO, NAUOShape, aRelatingPD, isDeepest );
1857 if ( anEntOfSHUO.IsNull() || NAUOShape.IsNull() ) {
1858#ifdef DEB
1859 cout << "Warning: " << __FILE__ << ": Cannot store SHUO" << endl;
1860#endif
1861 continue;
1862 }
1863 // create new Product Definition Shape for TOP SHUO
1864#ifdef DEB
1865 cout << "Info: " << __FILE__ << ": Create NEW PDS for current SHUO " << endl;
1866#endif
1867 Handle(StepRepr_ProductDefinitionShape) PDS = new StepRepr_ProductDefinitionShape;
1868 Handle(TCollection_HAsciiString) aPDSname = new TCollection_HAsciiString("SHUO");
1869 Handle(TCollection_HAsciiString) descrStr = new TCollection_HAsciiString("");
1870 StepRepr_CharacterizedDefinition aCharDef;
1871 aCharDef.SetValue( anEntOfSHUO );
1872 PDS->Init( aPDSname, Standard_False, descrStr, aCharDef );
1873
1874 // create styled item for SHUO and add to the model
1875 createSHUOStyledItem ( SHUOstyle, PDS, WS, NAUOShape, CTool->ShapeTool(), myMapCompMDGPR );
1876
1877 } // end work with SHUO
1878 } // end of an assembly components
1879 } // end of IsAssembly case
1880 // nothing to do if it is not assembly
1881 continue;
1882 } // end of iterates on indicated labels
1883 return Standard_True;
1884}
1885
1886
1887//=======================================================================
1888//function : FindPDSforDGT
1889//purpose : auxilary: find PDS for AdvancedFace or EdgeCurve for creation
1890// needed ShapeAspect in D&GT structure
1891//=======================================================================
1892static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph,
1893 const Handle(Standard_Transient) &ent,
1894 Handle(StepRepr_ProductDefinitionShape) &PDS,
1895 Handle(StepRepr_RepresentationContext) &RC,
1896 Handle(StepShape_AdvancedFace) &AF,
1897 Handle(StepShape_EdgeCurve) &EC)
1898{
1899 if( !ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) &&
1900 !ent->IsKind(STANDARD_TYPE(StepShape_AdvancedFace)) )
1901 return Standard_False;
1902
1903 AF = Handle(StepShape_AdvancedFace)::DownCast(ent);
1904 if( ent->IsKind(STANDARD_TYPE(StepShape_EdgeCurve)) ) {
1905 EC = Handle(StepShape_EdgeCurve)::DownCast(ent);
1906 Interface_EntityIterator subs = aGraph.Sharings(EC);
1907 for(subs.Start(); subs.More() && AF.IsNull(); subs.Next()) {
1908 Handle(StepShape_OrientedEdge) OE = Handle(StepShape_OrientedEdge)::DownCast(subs.Value());
1909 if(OE.IsNull()) continue;
1910 Interface_EntityIterator subs1 = aGraph.Sharings(OE);
1911 for(subs1.Start(); subs1.More() && AF.IsNull(); subs1.Next()) {
1912 Handle(StepShape_EdgeLoop) EL = Handle(StepShape_EdgeLoop)::DownCast(subs1.Value());
1913 if(EL.IsNull()) continue;
1914 Interface_EntityIterator subs2 = aGraph.Sharings(EL);
1915 for(subs2.Start(); subs2.More() && AF.IsNull(); subs2.Next()) {
1916 Handle(StepShape_FaceBound) FB = Handle(StepShape_FaceBound)::DownCast(subs2.Value());
1917 if(FB.IsNull()) continue;
1918 Interface_EntityIterator subs3 = aGraph.Sharings(FB);
1919 for(subs3.Start(); subs3.More() && AF.IsNull(); subs3.Next()) {
1920 AF = Handle(StepShape_AdvancedFace)::DownCast(subs3.Value());
1921 }
1922 }
1923 }
1924 }
1925 }
1926 if(AF.IsNull()) return Standard_False;
1927
1928 Interface_EntityIterator subs = aGraph.Sharings(AF);
1929 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
1930 Handle(StepShape_ConnectedFaceSet) CFS =
1931 Handle(StepShape_ConnectedFaceSet)::DownCast(subs.Value());
1932 if(CFS.IsNull()) continue;
1933 Interface_EntityIterator subs1 = aGraph.Sharings(CFS);
1934 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
1935 Handle(StepRepr_RepresentationItem) RI =
1936 Handle(StepRepr_RepresentationItem)::DownCast(subs1.Value());
1937 if(RI.IsNull()) continue;
1938 Interface_EntityIterator subs2 = aGraph.Sharings(RI);
1939 for(subs2.Start(); subs2.More() && PDS.IsNull(); subs2.Next()) {
1940 Handle(StepShape_ShapeRepresentation) SR =
1941 Handle(StepShape_ShapeRepresentation)::DownCast(subs2.Value());
1942 if(SR.IsNull()) continue;
1943 RC = SR->ContextOfItems();
1944 Interface_EntityIterator subs3 = aGraph.Sharings(SR);
1945 for(subs3.Start(); subs3.More() && PDS.IsNull(); subs3.Next()) {
1946 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
1947 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs3.Value());
1948 if(SDR.IsNull()) continue;
1949 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
1950 if(PropD.IsNull()) continue;
1951 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
1952 }
1953 }
1954 }
1955 }
1956
1957 return Standard_True;
1958}
1959
1960
1961//=======================================================================
1962//function : WriteDGTs
1963//purpose :
1964//=======================================================================
1965
1966Standard_Boolean STEPCAFControl_Writer::WriteDGTs (const Handle(XSControl_WorkSession) &WS,
1967 const TDF_LabelSequence &labels ) const
1968{
1969
1970 if ( labels.Length() <=0 ) return Standard_False;
1971
1972 // get working data
1973 Handle(Interface_InterfaceModel) Model = WS->Model();
1974 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
1975 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
1976 Interface_Graph aGraph = WS->HGraph()->Graph();
1977 Handle(XCAFDoc_DimTolTool) DGTTool = XCAFDoc_DocumentTool::DimTolTool( labels(1) );
1978 if(DGTTool.IsNull() ) return Standard_False;
1979
1980 TDF_LabelSequence DGTLabels;
1981 STEPConstruct_DataMapOfAsciiStringTransient DatumMap;
1982
1983 // write Datums
1984 DGTTool->GetDatumLabels(DGTLabels);
1985 if(DGTLabels.Length()<=0) return Standard_False;
1986 Standard_Integer i;
1987 for(i=1; i<=DGTLabels.Length(); i++) {
1988 TDF_Label DatumL = DGTLabels.Value(i);
1989 TDF_Label ShapeL;
1990 if(!DGTTool->GetRefShapeLabel(DatumL,ShapeL)) continue;
1991 // find target shape
1992 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL);
1993 TopLoc_Location Loc;
1994 TColStd_SequenceOfTransient seqRI;
1995 FindEntities( FP, aShape, Loc, seqRI );
1996 if ( seqRI.Length() <= 0 ) {
1997 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
1998 continue;
1999 }
2000 Handle(StepRepr_ProductDefinitionShape) PDS;
2001 Handle(StepRepr_RepresentationContext) RC;
2002 Handle(Standard_Transient) ent = seqRI.Value(1);
2003 Handle(StepShape_AdvancedFace) AF;
2004 Handle(StepShape_EdgeCurve) EC;
2005 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
2006 if(PDS.IsNull()) continue;
2007 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
2008 Handle(XCAFDoc_Datum) DatumAttr;
2009 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
2010 Handle(TCollection_HAsciiString) aName = DatumAttr->GetName();
2011 Handle(TCollection_HAsciiString) aDescription = DatumAttr->GetDescription();
2012 Handle(TCollection_HAsciiString) anIdentification = DatumAttr->GetIdentification();
2013 Handle(StepDimTol_DatumFeature) DF = new StepDimTol_DatumFeature;
2014 Handle(StepDimTol_Datum) aDatum = new StepDimTol_Datum;
2015 DF->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
2016 Model->AddWithRefs(DF);
2017 aDatum->Init(aName, new TCollection_HAsciiString, PDS, StepData_LFalse, anIdentification);
2018 Model->AddWithRefs(aDatum);
2019 Handle(StepRepr_ShapeAspectRelationship) SAR = new StepRepr_ShapeAspectRelationship;
2020 SAR->SetName(aName);
2021 SAR->SetRelatingShapeAspect(DF);
2022 SAR->SetRelatedShapeAspect(aDatum);
2023 Model->AddWithRefs(SAR);
2024 // write chain for DatumFeature
2025 StepRepr_CharacterizedDefinition CD;
2026 CD.SetValue(DF);
2027 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
2028 PropD->Init(aName,Standard_True,aDescription,CD);
2029 Model->AddWithRefs(PropD);
2030 StepRepr_RepresentedDefinition RD;
2031 RD.SetValue(PropD);
2032 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
2033 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2034 new StepRepr_HArray1OfRepresentationItem(1,1);
2035 HARI->SetValue(1,AF);
2036 SR->Init(aName,HARI,RC);
2037 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
2038 SDR->Init(RD,SR);
2039 Model->AddWithRefs(SDR);
2040 // write chain for Datum
2041 StepRepr_CharacterizedDefinition CD1;
2042 CD1.SetValue(aDatum);
2043 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
2044 PropD1->Init(aName,Standard_True,aDescription,CD1);
2045 Model->AddWithRefs(PropD1);
2046 StepRepr_RepresentedDefinition RD1;
2047 RD1.SetValue(PropD1);
2048 Handle(StepShape_ShapeRepresentation) SR1 = new StepShape_ShapeRepresentation;
2049 Handle(StepRepr_HArray1OfRepresentationItem) HARI1 =
2050 new StepRepr_HArray1OfRepresentationItem(1,1);
2051 HARI1->SetValue(1,AF->FaceGeometry());
2052 SR1->Init(aName,HARI1,RC);
2053 Model->AddWithRefs(SR1);
2054 Handle(StepShape_ShapeDefinitionRepresentation) SDR1 = new StepShape_ShapeDefinitionRepresentation;
2055 SDR1->Init(RD1,SR1);
2056 Model->AddWithRefs(SDR1);
2057 // add created Datum into Map
2058 TCollection_AsciiString stmp(aName->ToCString());
2059 stmp.AssignCat(aDescription->ToCString());
2060 stmp.AssignCat(anIdentification->ToCString());
2061 DatumMap.Bind(stmp,aDatum);
2062 }
2063
2064 // write Tolerances and Dimensions
2065 DGTLabels.Clear();
2066 DGTTool->GetDimTolLabels(DGTLabels);
2067 if(DGTLabels.Length()<=0) return Standard_False;
2068 for(i=1; i<=DGTLabels.Length(); i++) {
2069 TDF_Label DimTolL = DGTLabels.Value(i);
2070 TDF_Label ShapeL;
2071 if(!DGTTool->GetRefShapeLabel(DimTolL,ShapeL)) continue;
2072 // find target shape
2073 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShapeL);
2074 TopLoc_Location Loc;
2075 TColStd_SequenceOfTransient seqRI;
2076 FindEntities( FP, aShape, Loc, seqRI );
2077 if ( seqRI.Length() <= 0 ) {
2078 FP->Messenger() << "Warning: Cannot find RI for "<<aShape.TShape()->DynamicType()->Name()<<endl;
2079 continue;
2080 }
2081 Handle(StepRepr_ProductDefinitionShape) PDS;
2082 Handle(StepRepr_RepresentationContext) RC;
2083 Handle(Standard_Transient) ent = seqRI.Value(1);
2084 Handle(StepShape_AdvancedFace) AF;
2085 Handle(StepShape_EdgeCurve) EC;
2086 FindPDSforDGT(aGraph,ent,PDS,RC,AF,EC);
2087 if(PDS.IsNull()) continue;
2088 //cout<<"Model->Number(PDS)="<<Model->Number(PDS)<<endl;
2089
2090 Handle(XCAFDoc_DimTol) DimTolAttr;
2091 if(!DimTolL.FindAttribute(XCAFDoc_DimTol::GetID(),DimTolAttr)) continue;
2092 Standard_Integer kind = DimTolAttr->GetKind();
2093 Handle(TColStd_HArray1OfReal) aVal = DimTolAttr->GetVal();
2094 Handle(TCollection_HAsciiString) aName = DimTolAttr->GetName();
2095 Handle(TCollection_HAsciiString) aDescription = DimTolAttr->GetDescription();
2096
2097 // common part of writing D&GT entities
2098 StepRepr_CharacterizedDefinition CD;
2099 Handle(StepRepr_ShapeAspect) SA = new StepRepr_ShapeAspect;
2100 SA->Init(aName, new TCollection_HAsciiString, PDS, StepData_LTrue);
2101 Model->AddWithRefs(SA);
2102 CD.SetValue(SA);
2103 Handle(StepRepr_PropertyDefinition) PropD = new StepRepr_PropertyDefinition;
2104 PropD->Init(aName,Standard_True,aDescription,CD);
2105 Model->AddWithRefs(PropD);
2106 StepRepr_RepresentedDefinition RD;
2107 RD.SetValue(PropD);
2108 Handle(StepShape_ShapeRepresentation) SR = new StepShape_ShapeRepresentation;
2109 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2110 new StepRepr_HArray1OfRepresentationItem(1,1);
2111 if(kind<20)
2112 HARI->SetValue(1,EC);
2113 else
2114 HARI->SetValue(1,AF);
2115 SR->Init(aName,HARI,RC);
2116 Handle(StepShape_ShapeDefinitionRepresentation) SDR = new StepShape_ShapeDefinitionRepresentation;
2117 SDR->Init(RD,SR);
2118 Model->AddWithRefs(SDR);
2119 // define aUnit for creation LengthMeasureWithUnit (common for all)
2120 StepBasic_Unit aUnit;
2121 Handle(StepBasic_SiUnitAndLengthUnit) SLU;
2122 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext) Ctx =
2123 Handle(StepGeom_GeometricRepresentationContextAndGlobalUnitAssignedContext)::DownCast(RC);
2124 if(!Ctx.IsNull()) {
2125 for(Standard_Integer j=1; j<=Ctx->NbUnits(); j++) {
2126 if(Ctx->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2127 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx->UnitsValue(j));
2128 break;
2129 }
2130 }
2131 }
2132 if(SLU.IsNull()) {
2133 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx) Ctx1 =
2134 Handle(StepGeom_GeomRepContextAndGlobUnitAssCtxAndGlobUncertaintyAssCtx)::DownCast(RC);
2135 if(!Ctx1.IsNull()) {
2136 for(Standard_Integer j=1; j<=Ctx1->NbUnits(); j++) {
2137 if(Ctx1->UnitsValue(j)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit))) {
2138 SLU = Handle(StepBasic_SiUnitAndLengthUnit)::DownCast(Ctx1->UnitsValue(j));
2139 break;
2140 }
2141 }
2142 }
2143 }
2144 if(SLU.IsNull()) {
2145 SLU = new StepBasic_SiUnitAndLengthUnit;
2146 }
2147 aUnit.SetValue(SLU);
2148
2149 // specific part of writing D&GT entities
2150 if(kind<20) { //dimension
2151 Handle(StepShape_DimensionalSize) DimSize = new StepShape_DimensionalSize;
2152 DimSize->Init(SA,aDescription);
2153 Model->AddWithRefs(DimSize);
2154 if(aVal->Length()>1) {
2155 // create MeasureWithUnits
2156 Handle(StepBasic_MeasureValueMember) MVM1 = new StepBasic_MeasureValueMember;
2157 MVM1->SetName("POSITIVE_LENGTH_MEASURE");
2158 MVM1->SetReal(aVal->Value(1));
2159 Handle(StepBasic_MeasureWithUnit) MWU1 = new StepBasic_MeasureWithUnit;
2160 MWU1->Init(MVM1,aUnit);
2161 Handle(StepBasic_MeasureValueMember) MVM2 = new StepBasic_MeasureValueMember;
2162 MVM2->SetName("POSITIVE_LENGTH_MEASURE");
2163 MVM2->SetReal(aVal->Value(2));
2164 Handle(StepBasic_MeasureWithUnit) MWU2 = new StepBasic_MeasureWithUnit;
2165 MWU2->Init(MVM2,aUnit);
2166 Handle(StepRepr_RepresentationItem) RI1 = new StepRepr_RepresentationItem;
2167 RI1->Init(new TCollection_HAsciiString("lower limit"));
2168 Handle(StepRepr_RepresentationItem) RI2 = new StepRepr_RepresentationItem;
2169 RI2->Init(new TCollection_HAsciiString("upper limit"));
2170 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU1 =
2171 new StepRepr_ReprItemAndLengthMeasureWithUnit;
2172 RILMU1->Init(MWU1,RI1);
2173 Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) RILMU2 =
2174 new StepRepr_ReprItemAndLengthMeasureWithUnit;
2175 RILMU2->Init(MWU2,RI2);
2176 Model->AddWithRefs(RILMU1);
2177 Model->AddWithRefs(RILMU2);
2178 //Handle(StepRepr_CompoundItemDefinitionMember) CIDM =
2179 // new StepRepr_CompoundItemDefinitionMember;
2180 //Handle(TColStd_HArray1OfTransient) ArrTr = new TColStd_HArray1OfTransient(1,2);
2181 //ArrTr->SetValue(1,RILMU1);
2182 //ArrTr->SetValue(2,RILMU2);
2183 //CIDM->SetArrTransient(ArrTr);
2184 //CIDM->SetName("SET_REPRESENTATION_ITEM");
2185 //StepRepr_CompoundItemDefinition CID;
2186 //CID.SetValue(CIDM);
2187 Handle(StepRepr_HArray1OfRepresentationItem) HARIVR =
2188 new StepRepr_HArray1OfRepresentationItem(1,2);
2189 HARIVR->SetValue(1,RILMU1);
2190 HARIVR->SetValue(2,RILMU2);
2191 Handle(StepRepr_ValueRange) VR = new StepRepr_ValueRange;
2192 //VR->Init(aName,CID);
2193 VR->Init(aName,HARIVR);
2194 Model->AddEntity(VR);
2195 Handle(StepShape_ShapeDimensionRepresentation) SDimR =
2196 new StepShape_ShapeDimensionRepresentation;
2197 Handle(StepRepr_HArray1OfRepresentationItem) HARI =
2198 new StepRepr_HArray1OfRepresentationItem(1,1);
2199 HARI->SetValue(1,VR);
2200 SDimR->Init(aName,HARI,RC);
2201 Model->AddWithRefs(SDimR);
2202 Handle(StepShape_DimensionalCharacteristicRepresentation) DimCharR =
2203 new StepShape_DimensionalCharacteristicRepresentation;
2204 StepShape_DimensionalCharacteristic DimChar;
2205 DimChar.SetValue(DimSize);
2206 DimCharR->Init(DimChar,SDimR);
2207 Model->AddEntity(DimCharR);
2208 }
2209 }
2210 else if(kind<50) { //tolerance
2211 if(kind<35) { // tolerance with datum system
2212 TDF_LabelSequence DatumLabels;
2213 DGTTool->GetDatumTolerLabels(DimTolL,DatumLabels);
2214 Standard_Integer NbDR = DatumLabels.Length();
2215 Handle(StepDimTol_HArray1OfDatumReference) HADR = new StepDimTol_HArray1OfDatumReference(1,NbDR);
2216 for(Standard_Integer j=1; j<=NbDR; j++) {
2217 Handle(XCAFDoc_Datum) DatumAttr;
2218 TDF_Label DatumL = DatumLabels.Value(j);
2219 if(!DatumL.FindAttribute(XCAFDoc_Datum::GetID(),DatumAttr)) continue;
2220 Handle(TCollection_HAsciiString) aNameD = DatumAttr->GetName();
2221 Handle(TCollection_HAsciiString) aDescriptionD = DatumAttr->GetDescription();
2222 Handle(TCollection_HAsciiString) anIdentificationD = DatumAttr->GetIdentification();
2223 TCollection_AsciiString stmp(aNameD->ToCString());
2224 stmp.AssignCat(aDescriptionD->ToCString());
2225 stmp.AssignCat(anIdentificationD->ToCString());
2226 if(DatumMap.IsBound(stmp)) {
2227 Handle(StepDimTol_Datum) aDatum =
2228 Handle(StepDimTol_Datum)::DownCast(DatumMap.Find(stmp));
2229 Handle(StepDimTol_DatumReference) DR = new StepDimTol_DatumReference;
2230 DR->Init(j,aDatum);
2231 Model->AddWithRefs(DR);
2232 HADR->SetValue(j,DR);
2233 }
2234 }
2235 // create LengthMeasureWithUnit
2236 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
2237 MVM->SetName("LENGTH_MEASURE");
2238 MVM->SetReal(aVal->Value(1));
2239 Handle(StepBasic_LengthMeasureWithUnit) LMWU = new StepBasic_LengthMeasureWithUnit;
2240 LMWU->Init(MVM,aUnit);
2241 // create tolerance by it's type
2242 if(kind<24) {
2243 Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
2244 new StepDimTol_GeometricToleranceWithDatumReference;
2245 GTWDR->SetDatumSystem(HADR);
2246 Handle(StepDimTol_ModifiedGeometricTolerance) MGT =
2247 new StepDimTol_ModifiedGeometricTolerance;
2248 if(kind==21) MGT->SetModifier(StepDimTol_MaximumMaterialCondition);
2249 else if(kind==22) MGT->SetModifier(StepDimTol_LeastMaterialCondition);
2250 else if(kind==23) MGT->SetModifier(StepDimTol_RegardlessOfFeatureSize);
2251 Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol) GTComplex =
2252 new StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol;
2253 GTComplex->Init(aName,aDescription,LMWU,SA,GTWDR,MGT);
2254 Model->AddWithRefs(GTComplex);
2255 }
2256 else if(kind==24) {
2257 Handle(StepDimTol_AngularityTolerance) aToler =
2258 new StepDimTol_AngularityTolerance;
2259 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2260 Model->AddWithRefs(aToler);
2261 }
2262 else if(kind==25) {
2263 Handle(StepDimTol_CircularRunoutTolerance) aToler =
2264 new StepDimTol_CircularRunoutTolerance;
2265 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2266 Model->AddWithRefs(aToler);
2267 }
2268 else if(kind==26) {
2269 Handle(StepDimTol_CoaxialityTolerance) aToler =
2270 new StepDimTol_CoaxialityTolerance;
2271 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2272 Model->AddWithRefs(aToler);
2273 }
2274 else if(kind==27) {
2275 Handle(StepDimTol_ConcentricityTolerance) aToler =
2276 new StepDimTol_ConcentricityTolerance;
2277 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2278 Model->AddWithRefs(aToler);
2279 }
2280 else if(kind==28) {
2281 Handle(StepDimTol_ParallelismTolerance) aToler =
2282 new StepDimTol_ParallelismTolerance;
2283 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2284 Model->AddWithRefs(aToler);
2285 }
2286 else if(kind==29) {
2287 Handle(StepDimTol_PerpendicularityTolerance) aToler =
2288 new StepDimTol_PerpendicularityTolerance;
2289 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2290 Model->AddWithRefs(aToler);
2291 }
2292 else if(kind==30) {
2293 Handle(StepDimTol_SymmetryTolerance) aToler =
2294 new StepDimTol_SymmetryTolerance;
2295 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2296 Model->AddWithRefs(aToler);
2297 }
2298 else if(kind==31) {
2299 Handle(StepDimTol_TotalRunoutTolerance) aToler =
2300 new StepDimTol_TotalRunoutTolerance;
2301 aToler->Init(aName,aDescription,LMWU,SA,HADR);
2302 Model->AddWithRefs(aToler);
2303 }
2304 }
2305 }
2306 }
2307
2308 return Standard_True;
2309}
2310
2311
2312//=======================================================================
2313//function : FindPDSforRI
2314//purpose : auxilary:
2315//=======================================================================
2316static Standard_Boolean FindPDSforRI(const Interface_Graph &aGraph,
2317 const Handle(Standard_Transient) &ent,
2318 Handle(StepRepr_ProductDefinitionShape) &PDS,
2319 Handle(StepRepr_RepresentationContext) &RC)
2320{
2321 if(!ent->IsKind(STANDARD_TYPE(StepRepr_RepresentationItem))) return Standard_False;
2322 Interface_EntityIterator subs = aGraph.Sharings(ent);
2323 for(subs.Start(); subs.More() && PDS.IsNull(); subs.Next()) {
2324 Handle(StepShape_ShapeRepresentation) SR =
2325 Handle(StepShape_ShapeRepresentation)::DownCast(subs.Value());
2326 if(SR.IsNull()) continue;
2327 RC = SR->ContextOfItems();
2328 Interface_EntityIterator subs1 = aGraph.Sharings(SR);
2329 for(subs1.Start(); subs1.More() && PDS.IsNull(); subs1.Next()) {
2330 Handle(StepShape_ShapeDefinitionRepresentation) SDR =
2331 Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs1.Value());
2332 if(SDR.IsNull()) continue;
2333 Handle(StepRepr_PropertyDefinition) PropD = SDR->Definition().PropertyDefinition();
2334 if(PropD.IsNull()) continue;
2335 PDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(PropD);
2336 }
2337 }
2338 return Standard_True;
2339}
2340
2341
2342//=======================================================================
2343//function : WriteMaterials
2344//purpose :
2345//=======================================================================
2346
2347Standard_Boolean STEPCAFControl_Writer::WriteMaterials (const Handle(XSControl_WorkSession) &WS,
2348 const TDF_LabelSequence &labels ) const
2349{
2350
2351 if ( labels.Length() <=0 ) return Standard_False;
2352
2353 // get working data
2354 Handle(Interface_InterfaceModel) Model = WS->Model();
2355 Handle(XSControl_TransferWriter) TW = WS->TransferWriter();
2356 Handle(Transfer_FinderProcess) FP = TW->FinderProcess();
2357 Interface_Graph aGraph = WS->HGraph()->Graph();
2358 Handle(XCAFDoc_ShapeTool) ShTool = XCAFDoc_DocumentTool::ShapeTool( labels(1) );
2359 if(ShTool.IsNull() ) return Standard_False;
2360 Handle(XCAFDoc_MaterialTool) MatTool = XCAFDoc_DocumentTool::MaterialTool( labels(1) );
2361 if(MatTool.IsNull() ) return Standard_False;
2362
2363 STEPConstruct_DataMapOfAsciiStringTransient MapDRI,MapMRI;
2364 TDF_LabelSequence TopLabels;
2365 ShTool->GetShapes(TopLabels);
2366 for(Standard_Integer i=1; i<=TopLabels.Length(); i++) {
2367 TDF_Label ShL = TopLabels.Value(i);
2368 Handle(TDataStd_TreeNode) Node;
2369 if( ShL.FindAttribute(XCAFDoc::MaterialRefGUID(),Node) && Node->HasFather() ) {
2370 // find PDS for current shape
2371 TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(ShL);
2372 TopLoc_Location Loc;
2373 TColStd_SequenceOfTransient seqRI;
2374 FindEntities( FP, aShape, Loc, seqRI );
2375 if(seqRI.Length()<=0) continue;
2376 Handle(StepRepr_ProductDefinitionShape) PDS;
2377 Handle(StepRepr_RepresentationContext) RC;
2378 Handle(Standard_Transient) ent = seqRI.Value(1);
2379 FindPDSforRI(aGraph,ent,PDS,RC);
2380 if(PDS.IsNull()) continue;
1d2b1ccb
G
2381 Handle(StepBasic_ProductDefinition) aProdDef =
2382 PDS->Definition().ProductDefinition();
2383 if(aProdDef.IsNull())
2384 continue;
7fd59977 2385 // write material entities
2386 TDF_Label MatL = Node->Father()->Label();
2387 Handle(TCollection_HAsciiString) aName;
2388 Handle(TCollection_HAsciiString) aDescription;
2389 Standard_Real aDensity;
2390 Handle(TCollection_HAsciiString) aDensName;
2391 Handle(TCollection_HAsciiString) aDensValType;
2392 Handle(StepRepr_Representation) RepDRI = new StepRepr_Representation;
2393 Handle(StepRepr_Representation) RepMRI = new StepRepr_Representation;
2394 if(MatTool->GetMaterial(MatL,aName,aDescription,aDensity,aDensName,aDensValType)) {
2395 if(aName->Length()==0) continue;
2396 TCollection_AsciiString aKey(aName->ToCString());
2397 if(MapDRI.IsBound(aKey)) {
2398 RepDRI = Handle(StepRepr_Representation)::DownCast(MapDRI.Find(aKey));
2399 if(MapMRI.IsBound(aKey)) {
2400 RepMRI = Handle(StepRepr_Representation)::DownCast(MapMRI.Find(aKey));
2401 }
2402 }
2403 else {
2404 // write DRI
2405 Handle(StepRepr_DescriptiveRepresentationItem) DRI = new StepRepr_DescriptiveRepresentationItem;
2406 DRI->Init(aName,aDescription);
2407 Handle(StepRepr_HArray1OfRepresentationItem) HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
2408 HARI->SetValue(1,DRI);
2409 RepDRI->Init(new TCollection_HAsciiString("material name"),HARI,RC);
2410 Model->AddWithRefs(RepDRI);
2411 // write MRI
2412 if(aDensity>0) {
2413 // mass
2414 Handle(StepBasic_SiUnitAndMassUnit) SMU = new StepBasic_SiUnitAndMassUnit;
2415 SMU->SetName(StepBasic_sunGram);
2416 Handle(StepBasic_DerivedUnitElement) DUE1 = new StepBasic_DerivedUnitElement;
2417 DUE1->Init(SMU,3.0);
2418 // length
2419 Handle(StepBasic_SiUnitAndLengthUnit) SLU = new StepBasic_SiUnitAndLengthUnit;
2420 SLU->Init(Standard_True,StepBasic_spCenti,StepBasic_sunMetre);
2421 Handle(StepBasic_DerivedUnitElement) DUE2 = new StepBasic_DerivedUnitElement;
2422 DUE2->Init(SLU,2.0);
2423 // other
2424 Handle(StepBasic_HArray1OfDerivedUnitElement) HADUE = new StepBasic_HArray1OfDerivedUnitElement(1,2);
2425 HADUE->SetValue(1,DUE1);
2426 HADUE->SetValue(2,DUE2);
2427 Handle(StepBasic_DerivedUnit) DU = new StepBasic_DerivedUnit;
2428 DU->Init(HADUE);
2429 Model->AddWithRefs(DU);
2430 StepBasic_Unit aUnit;
2431 aUnit.SetValue(DU);
2432 Handle(StepBasic_MeasureValueMember) MVM = new StepBasic_MeasureValueMember;
2433 MVM->SetName(aDensValType->ToCString());
2434 MVM->SetReal(aDensity);
2435 Handle(StepRepr_MeasureRepresentationItem) MRI = new StepRepr_MeasureRepresentationItem;
2436 MRI->Init(aDensName,MVM,aUnit);
2437 HARI = new StepRepr_HArray1OfRepresentationItem(1,1);
2438 HARI->SetValue(1,MRI);
2439 RepMRI->Init(new TCollection_HAsciiString("density"),HARI,RC);
2440 Model->AddWithRefs(RepMRI);
2441 }
2442 //WriteNewMaterial(Model,aName,aDescription,aDensity,aDensName,aDensValType,RC,RepDRI,RepMRI);
2443 MapDRI.Bind(aKey,RepDRI);
2444 if(!RepMRI.IsNull()) MapMRI.Bind(aKey,RepMRI);
2445 }
2446 }
2447 // write chain PDS---(DRI,MRI)
2448 StepRepr_CharacterizedDefinition CD1;
1d2b1ccb 2449 CD1.SetValue(aProdDef);
7fd59977 2450 Handle(StepRepr_PropertyDefinition) PropD1 = new StepRepr_PropertyDefinition;
2451 PropD1->Init(new TCollection_HAsciiString("material property"),Standard_True,
2452 new TCollection_HAsciiString("material name"),CD1);
2453 Model->AddWithRefs(PropD1);
2454 StepRepr_RepresentedDefinition RD1;
2455 RD1.SetValue(PropD1);
2456 Handle(StepRepr_PropertyDefinitionRepresentation) PDR1 =
2457 new StepRepr_PropertyDefinitionRepresentation;
2458 PDR1->Init(RD1,RepDRI);
2459 Model->AddWithRefs(PDR1);
2460 StepRepr_CharacterizedDefinition CD2;
1d2b1ccb 2461 CD2.SetValue(aProdDef);
7fd59977 2462 Handle(StepRepr_PropertyDefinition) PropD2 = new StepRepr_PropertyDefinition;
2463 PropD2->Init(new TCollection_HAsciiString("material property"),Standard_True,
2464 new TCollection_HAsciiString("density"),CD2);
2465 Model->AddWithRefs(PropD2);
2466 StepRepr_RepresentedDefinition RD2;
2467 RD2.SetValue(PropD2);
2468 Handle(StepRepr_PropertyDefinitionRepresentation) PDR2 =
2469 new StepRepr_PropertyDefinitionRepresentation;
2470 PDR2->Init(RD2,RepMRI);
2471 Model->AddWithRefs(PDR2);
2472 }
2473 }
2474
2475 return Standard_True;
2476}
2477
2478
2479//=======================================================================
2480//function : SetColorMode
2481//purpose :
2482//=======================================================================
2483
2484void STEPCAFControl_Writer::SetColorMode (const Standard_Boolean colormode)
2485{
2486 myColorMode = colormode;
2487}
2488
2489
2490//=======================================================================
2491//function : GetColorMode
2492//purpose :
2493//=======================================================================
2494
2495Standard_Boolean STEPCAFControl_Writer::GetColorMode () const
2496{
2497 return myColorMode;
2498}
2499
2500
2501//=======================================================================
2502//function : SetNameMode
2503//purpose :
2504//=======================================================================
2505
2506void STEPCAFControl_Writer::SetNameMode (const Standard_Boolean namemode)
2507{
2508 myNameMode = namemode;
2509}
2510
2511
2512//=======================================================================
2513//function : GetNameMode
2514//purpose :
2515//=======================================================================
2516
2517Standard_Boolean STEPCAFControl_Writer::GetNameMode () const
2518{
2519 return myNameMode;
2520}
2521
2522
2523//=======================================================================
2524//function : SetLayerMode
2525//purpose :
2526//=======================================================================
2527
2528void STEPCAFControl_Writer::SetLayerMode (const Standard_Boolean layermode)
2529{
2530 myLayerMode = layermode;
2531}
2532
2533
2534//=======================================================================
2535//function : GetLayerMode
2536//purpose :
2537//=======================================================================
2538
2539Standard_Boolean STEPCAFControl_Writer::GetLayerMode () const
2540{
2541 return myLayerMode;
2542}
2543
2544
2545//=======================================================================
2546//function : SetPropsMode
2547//purpose :
2548//=======================================================================
2549
2550void STEPCAFControl_Writer::SetPropsMode (const Standard_Boolean propsmode)
2551{
2552 myPropsMode = propsmode;
2553}
2554
2555
2556//=======================================================================
2557//function : GetPropsMode
2558//purpose :
2559//=======================================================================
2560
2561Standard_Boolean STEPCAFControl_Writer::GetPropsMode () const
2562{
2563 return myPropsMode;
2564}
2565
2566
2567//=======================================================================
2568//function : SetSHUOMode
2569//purpose :
2570//=======================================================================
2571
2572void STEPCAFControl_Writer::SetSHUOMode (const Standard_Boolean mode)
2573{
2574 mySHUOMode = mode;
2575}
2576
2577
2578//=======================================================================
2579//function : GetSHUOMode
2580//purpose :
2581//=======================================================================
2582
2583Standard_Boolean STEPCAFControl_Writer::GetSHUOMode () const
2584{
2585 return mySHUOMode;
2586}
2587
2588
2589//=======================================================================
2590//function : SetDimTolMode
2591//purpose :
2592//=======================================================================
2593
2594void STEPCAFControl_Writer::SetDimTolMode(const Standard_Boolean dimtolmode)
2595{
2596 myDGTMode = dimtolmode;
2597}
2598
2599
2600//=======================================================================
2601//function : GetDimTolMode
2602//purpose :
2603//=======================================================================
2604
2605Standard_Boolean STEPCAFControl_Writer::GetDimTolMode() const
2606{
2607 return myDGTMode;
2608}
2609
2610
2611//=======================================================================
2612//function : SetMaterialMode
2613//purpose :
2614//=======================================================================
2615
2616void STEPCAFControl_Writer::SetMaterialMode(const Standard_Boolean matmode)
2617{
2618 myMatMode = matmode;
2619}
2620
2621
2622//=======================================================================
2623//function : GetMaterialMode
2624//purpose :
2625//=======================================================================
2626
2627Standard_Boolean STEPCAFControl_Writer::GetMaterialMode() const
2628{
2629 return myMatMode;
2630}