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