0031550: Data Exchange, STEP Import - surface transparency is ignored (SURFACE_STYLE_...
[occt.git] / src / STEPConstruct / STEPConstruct_Styles.cxx
CommitLineData
b311480e 1// Created on: 1999-09-10
2// Created by: Andrey BETENEV
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <APIHeaderSection_MakeHeader.hxx>
19#include <gp_Pnt.hxx>
20#include <Interface_EntityIterator.hxx>
7fd59977 21#include <Interface_Graph.hxx>
7fd59977 22#include <Interface_InterfaceModel.hxx>
42cf5bc1 23#include <Interface_Static.hxx>
24#include <Quantity_Color.hxx>
25#include <StepBasic_MeasureValueMember.hxx>
26#include <STEPConstruct.hxx>
27#include <STEPConstruct_Styles.hxx>
28#include <StepData_StepModel.hxx>
7fd59977 29#include <StepGeom_GeometricRepresentationItem.hxx>
42cf5bc1 30#include <StepRepr_HArray1OfRepresentationItem.hxx>
31#include <StepRepr_ItemDefinedTransformation.hxx>
32#include <StepRepr_ProductDefinitionShape.hxx>
33#include <StepRepr_Representation.hxx>
34#include <StepRepr_RepresentationContext.hxx>
35#include <StepRepr_RepresentationItem.hxx>
36#include <StepRepr_RepresentationRelationshipWithTransformation.hxx>
37#include <StepRepr_ShapeRepresentationRelationship.hxx>
38#include <StepRepr_Transformation.hxx>
39#include <StepShape_ContextDependentShapeRepresentation.hxx>
40#include <StepShape_ShapeDefinitionRepresentation.hxx>
7fd59977 41#include <StepShape_ShapeRepresentation.hxx>
42cf5bc1 42#include <StepVisual_Colour.hxx>
7fd59977 43#include <StepVisual_ColourRgb.hxx>
42cf5bc1 44#include <StepVisual_CurveStyle.hxx>
45#include <StepVisual_DraughtingModel.hxx>
46#include <StepVisual_DraughtingPreDefinedColour.hxx>
47#include <StepVisual_DraughtingPreDefinedCurveFont.hxx>
48#include <StepVisual_FillAreaStyle.hxx>
7fd59977 49#include <StepVisual_FillAreaStyleColour.hxx>
50#include <StepVisual_FillStyleSelect.hxx>
51#include <StepVisual_HArray1OfFillStyleSelect.hxx>
7fd59977 52#include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
42cf5bc1 53#include <StepVisual_HArray1OfPresentationStyleSelect.hxx>
54#include <StepVisual_HArray1OfSurfaceStyleElementSelect.hxx>
55#include <StepVisual_Invisibility.hxx>
56#include <StepVisual_InvisibleItem.hxx>
7fd59977 57#include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
42cf5bc1 58#include <StepVisual_OverRidingStyledItem.hxx>
7fd59977 59#include <StepVisual_PreDefinedColour.hxx>
60#include <StepVisual_PreDefinedItem.hxx>
42cf5bc1 61#include <StepVisual_PresentationStyleAssignment.hxx>
7fd59977 62#include <StepVisual_PresentationStyleByContext.hxx>
42cf5bc1 63#include <StepVisual_PresentationStyleSelect.hxx>
64#include <StepVisual_StyledItem.hxx>
65#include <StepVisual_SurfaceSideStyle.hxx>
66#include <StepVisual_SurfaceStyleBoundary.hxx>
67#include <StepVisual_SurfaceStyleElementSelect.hxx>
68#include <StepVisual_SurfaceStyleFillArea.hxx>
691711cd
IK
69#include <StepVisual_SurfaceStyleRendering.hxx>
70#include <StepVisual_SurfaceStyleRenderingWithProperties.hxx>
71#include <StepVisual_RenderingPropertiesSelect.hxx>
72#include <StepVisual_SurfaceStyleTransparent.hxx>
42cf5bc1 73#include <StepVisual_SurfaceStyleUsage.hxx>
74#include <TCollection_HAsciiString.hxx>
7fd59977 75#include <TColStd_HSequenceOfTransient.hxx>
42cf5bc1 76#include <TopoDS_Shape.hxx>
77#include <Transfer_Binder.hxx>
78#include <TransferBRep.hxx>
79#include <TransferBRep_ShapeMapper.hxx>
80#include <XSControl_TransferReader.hxx>
81#include <XSControl_TransferWriter.hxx>
82#include <XSControl_WorkSession.hxx>
7fd59977 83
84//=======================================================================
85//function : STEPConstruct_Styles
86//purpose :
87//=======================================================================
7fd59977 88STEPConstruct_Styles::STEPConstruct_Styles ()
89{
90}
91
92
93//=======================================================================
94//function : STEPConstruct_Styles
95//purpose :
96//=======================================================================
97
98STEPConstruct_Styles::STEPConstruct_Styles (const Handle(XSControl_WorkSession) &WS)
99 : STEPConstruct_Tool ( WS )
100{
101}
102
103
104//=======================================================================
105//function : Init
106//purpose :
107//=======================================================================
108
109Standard_Boolean STEPConstruct_Styles::Init (const Handle(XSControl_WorkSession) &WS)
110{
111 myMapOfStyles.Clear();
112 myStyles.Clear();
113 myPSA.Clear();
114 return SetWS ( WS );
115}
116
117
118//=======================================================================
119//function : NbStyles
120//purpose :
121//=======================================================================
122
123Standard_Integer STEPConstruct_Styles::NbStyles () const
124{
ec661e43 125 return myStyles.Extent();
7fd59977 126}
127
128
129//=======================================================================
130//function : Style
131//purpose :
132//=======================================================================
133
134Handle(StepVisual_StyledItem) STEPConstruct_Styles::Style (const Standard_Integer i) const
135{
ec661e43 136 return Handle(StepVisual_StyledItem)::DownCast ( myStyles.FindKey(i) );
7fd59977 137}
138
139
140//=======================================================================
141//function : ClearStyles
142//purpose :
143//=======================================================================
144
145void STEPConstruct_Styles::ClearStyles ()
146{
147 myStyles.Clear();
148 myPSA.Clear();
149}
150
151
152//=======================================================================
153//function : AddStyle
154//purpose :
155//=======================================================================
156
157void STEPConstruct_Styles::AddStyle (const Handle(StepVisual_StyledItem) &style)
158{
ec661e43 159 myStyles.Add ( style );
7fd59977 160}
161
162
163//=======================================================================
164//function : AddStyle
165//purpose :
166//=======================================================================
167
168Handle(StepVisual_StyledItem) STEPConstruct_Styles::AddStyle (const Handle(StepRepr_RepresentationItem) &item,
169 const Handle(StepVisual_PresentationStyleAssignment) &PSA,
170 const Handle(StepVisual_StyledItem) &Override)
171{
172 Handle(StepVisual_StyledItem) Style;
173
174 Handle(StepVisual_HArray1OfPresentationStyleAssignment) Styles =
175 new StepVisual_HArray1OfPresentationStyleAssignment ( 1, 1 );
176 Styles->SetValue ( 1, PSA );
177
178 if ( Override.IsNull() ) {
179 Handle(TCollection_HAsciiString) StyName = new TCollection_HAsciiString ( "color" );
180 Style = new StepVisual_StyledItem;
181 Style->Init ( StyName, Styles, item );
182 }
183 else {
184 Handle(TCollection_HAsciiString) StyName = new TCollection_HAsciiString ( "overriding color" );
185 Handle(StepVisual_OverRidingStyledItem) OStyle = new StepVisual_OverRidingStyledItem;
186 OStyle->Init ( StyName, Styles, item, Override );
187 Style = OStyle;
188 }
189
ec661e43 190 myStyles.Add ( Style );
7fd59977 191 // for future using
192 myPSA.Append( PSA );
193
194 return Style;
195}
196
197
198//=======================================================================
199//function : AddStyle
200//purpose :
201//=======================================================================
202
203Handle(StepVisual_StyledItem) STEPConstruct_Styles::AddStyle (const TopoDS_Shape &Shape,
204 const Handle(StepVisual_PresentationStyleAssignment) &PSA,
205 const Handle(StepVisual_StyledItem) &Override)
206{
207 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FinderProcess(), Shape );
208 Handle(StepVisual_StyledItem) Style;
209 if ( ! item.IsNull() ) Style = AddStyle ( item, PSA, Override );
210 return Style;
211}
212
213
214//=======================================================================
215//function : CreateMDGPR
216//purpose :
217//=======================================================================
218
219Standard_Boolean STEPConstruct_Styles::CreateMDGPR (const Handle(StepRepr_RepresentationContext) &Context,
220 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)& Repr)
221{
ec661e43 222 if ( myStyles.Extent() <1 ) return Standard_False;
7fd59977 223
224 // create MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION
225 Handle(StepRepr_HArray1OfRepresentationItem) elems =
ec661e43 226 new StepRepr_HArray1OfRepresentationItem ( 1, myStyles.Extent() );
227 for ( Standard_Integer i=1; i <= myStyles.Extent(); i++ )
228 elems->SetValue ( i, Handle(StepRepr_RepresentationItem)::DownCast ( myStyles.FindKey(i) ) );
7fd59977 229 // create new MDGPR
230 Repr = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
231 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
232 Repr->Init ( ReprName, elems, Context );
233
234 // record Repr in order to have it written to the file
235// Model()->AddWithRefs ( Repr ); add into the model upper
236
237 // for AP203, add subschema name
238 if ( Interface_Static::IVal("write.step.schema") ==3 ) {
239 APIHeaderSection_MakeHeader mkHdr ( Handle(StepData_StepModel)::DownCast ( Model() ) );
240 Handle(TCollection_HAsciiString) subSchema =
241 new TCollection_HAsciiString ( "SHAPE_APPEARANCE_LAYER_MIM" );
242 mkHdr.AddSchemaIdentifier ( subSchema );
243 }
244
245 return Standard_True;
246}
247
248
249//=======================================================================
250//function : CreateNAUOSRD
251//purpose :
252//=======================================================================
253
254Standard_Boolean STEPConstruct_Styles::CreateNAUOSRD (const Handle(StepRepr_RepresentationContext) &Context,
255 const Handle(StepShape_ContextDependentShapeRepresentation)& CDSR,
256 const Handle(StepRepr_ProductDefinitionShape)& initPDS)
257{
258 Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
259 new StepShape_ShapeDefinitionRepresentation;
260 Handle(StepShape_ShapeRepresentation) aSR =
261 new StepShape_ShapeRepresentation;
262 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
263 // element for axis 2 placement
264 Handle(StepRepr_HArray1OfRepresentationItem) elems =
265 new StepRepr_HArray1OfRepresentationItem ( 1, 1 );
266 // get PDS
267 Handle(StepRepr_ProductDefinitionShape) aPDS;
268 if ( initPDS.IsNull() )
269 aPDS = CDSR->RepresentedProductRelation();
270 else
271 aPDS = initPDS; // for SHUO
272 Handle(StepRepr_ShapeRepresentationRelationship) aRepRelationShip = CDSR->RepresentationRelation();
273 Handle(StepRepr_RepresentationRelationshipWithTransformation) aRRwTRSF =
274 Handle(StepRepr_RepresentationRelationshipWithTransformation)::DownCast(aRepRelationShip);
275 StepRepr_Transformation SetReprTRSF;
276 if (!aRRwTRSF.IsNull())
277 SetReprTRSF = aRRwTRSF->TransformationOperator();
278 else
279 return Standard_False;
280 // take Item defined transformation
281 Handle(StepRepr_ItemDefinedTransformation) anItDT = SetReprTRSF.ItemDefinedTransformation();
282 elems->SetValue( 1, anItDT->TransformItem2() );
283 // init Shape representation.
284 aSR->Init ( ReprName, elems, Context );
285 // register reference between PresentationStyleByContext and ShapeRepresentation
286 for (Standard_Integer psbci = 1; psbci <= myPSA.Length(); psbci++) {
287 Handle(StepVisual_PresentationStyleByContext) PSA =
288 Handle(StepVisual_PresentationStyleByContext)::DownCast(myPSA.Value(psbci));
289 if (PSA.IsNull())
290 continue;
291 // register the reference
292 StepVisual_StyleContextSelect aStyleCntxSlct;
293 aStyleCntxSlct.SetValue( aSR );
294 PSA->SetStyleContext( aStyleCntxSlct );
295 }
296
297 StepRepr_RepresentedDefinition aPDSselect;
298 aPDSselect.SetValue(aPDS);
299 aSDR->Init( aPDSselect, aSR );
300 Model()->AddWithRefs ( aSDR );
301
302 return Standard_True;
303}
304
305
306//=======================================================================
307//function : FindContext
308//purpose :
309//=======================================================================
310
311Handle(StepRepr_RepresentationContext) STEPConstruct_Styles::FindContext (const TopoDS_Shape &Shape) const
312{
313 // find context of items
314 Handle(StepRepr_RepresentationContext) Context;
315 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess(), Shape );
316 Handle(StepShape_ShapeRepresentation) sr;
317 if ( FinderProcess()->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ShapeRepresentation), sr) ) {
0797d9d3 318#ifdef OCCT_DEBUG
04232180 319// std::cout << "Context of " << Shape.TShape()->DynamicType()->Name() << ": SR found: " << sr->DynamicType()->Name() << std::endl;
7fd59977 320#endif
321 Context = sr->ContextOfItems();
322 }
323 else {
324 Handle(StepGeom_GeometricRepresentationItem) item;
325 if ( FinderProcess()->FindTypedTransient (mapper,STANDARD_TYPE(StepGeom_GeometricRepresentationItem), item) ) {
0797d9d3 326#ifdef OCCT_DEBUG
04232180 327// std::cout << "Context of " << Shape.TShape()->DynamicType()->Name() << ": GeomRepItem found: " << item->DynamicType()->Name() << std::endl;
7fd59977 328#endif
329 Interface_EntityIterator subs = Graph().Sharings(item);
330 for (subs.Start(); Context.IsNull() && subs.More(); subs.Next()) {
0797d9d3 331#ifdef OCCT_DEBUG
04232180 332// std::cout << "Parsing back refs: found " << subs.Value()->DynamicType()->Name() << std::endl;
7fd59977 333#endif
334 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation)) ) continue;
335 sr = Handle(StepShape_ShapeRepresentation)::DownCast ( subs.Value() );
336 Context = sr->ContextOfItems();
337 }
338 }
339 }
0797d9d3 340#ifdef OCCT_DEBUG
7fd59977 341 if ( Context.IsNull() ) {
04232180 342 std::cout << Shape.TShape()->DynamicType()->Name() << ": Cannot find context" << std::endl;
7fd59977 343 }
344#endif
345
346 return Context;
347}
348
349
350//=======================================================================
351//function : LoadStyles
352//purpose :
353//=======================================================================
354
355Standard_Boolean STEPConstruct_Styles::LoadStyles ()
356{
357 myStyles.Clear();
358 myPSA.Clear();
359
360 // find all MDGPRs and DMs and collect all defined styles in myStyles
361 Handle(Interface_InterfaceModel) model = Model();
362 Standard_Integer nb = model->NbEntities();
363 Handle(Standard_Type) tMDGPR = STANDARD_TYPE(StepVisual_MechanicalDesignGeometricPresentationRepresentation);
364 Handle(Standard_Type) tDM = STANDARD_TYPE(StepVisual_DraughtingModel);
ec661e43 365 Handle(Standard_Type) tSI = STANDARD_TYPE(StepVisual_StyledItem);
366 for (Standard_Integer i = 1; i <= nb; i ++)
367 {
7fd59977 368 Handle(Standard_Transient) enti = model->Value(i);
ec661e43 369 if ( enti->DynamicType() == tMDGPR || enti->DynamicType() == tDM )
370 {
371 Handle(StepRepr_Representation) container = Handle(StepRepr_Representation)::DownCast ( enti );
372
373 Standard_Integer nbi = container->NbItems();
374 for ( Standard_Integer j=1; j <= nbi; j++ )
375 {
376 Handle(StepVisual_StyledItem) style =
377 Handle(StepVisual_StyledItem)::DownCast ( container->ItemsValue(j) );
378 if ( style.IsNull() ) continue;
379 myStyles.Add ( style );
380 }
381 }
382 else if (enti->DynamicType() == tSI)
383 {
384 Handle(StepVisual_StyledItem) aStyledItem = Handle(StepVisual_StyledItem)::DownCast (enti);
385 if (!myStyles.Contains (aStyledItem))
386 {
387 myStyles.Add (aStyledItem);
388 }
7fd59977 389 }
390 }
ec661e43 391 return !myStyles.IsEmpty();
7fd59977 392}
393
394
395//=======================================================================
396//function : LoadInvisStyles
397//purpose :
398//=======================================================================
399
400Standard_Boolean STEPConstruct_Styles::LoadInvisStyles (Handle(TColStd_HSequenceOfTransient)& theInvStyles) const
401{
402 Handle(Interface_InterfaceModel) model = Model();
403 Standard_Integer nb = model->NbEntities();
404 Handle(Standard_Type) tInvisibility = STANDARD_TYPE(StepVisual_Invisibility);
405 // serach for invisibility
406 for (Standard_Integer i = 1; i <= nb; i ++) {
407 Handle(Standard_Transient) enti = model->Value(i);
408 if ( enti->DynamicType() != tInvisibility )
409 continue;
410 // search for styled items
411 Handle(StepVisual_Invisibility) container = Handle(StepVisual_Invisibility)::DownCast ( enti );
412 Standard_Integer nbi = container->NbInvisibleItems();
413 for ( Standard_Integer j=1; j <= nbi; j++ ) {
414 StepVisual_InvisibleItem anInvItem = container->InvisibleItemsValue(j);
415 Handle(StepVisual_StyledItem) style = anInvItem.StyledItem();
416 if ( style.IsNull() )
417 continue;
418 // collect the invisible styled items
419 if ( theInvStyles.IsNull() )
420 theInvStyles = new TColStd_HSequenceOfTransient;
421 theInvStyles->Append( style );
422 }
423 }
424 return ( !theInvStyles.IsNull() && (theInvStyles->Length() > 0) );
425}
426
427
428//=======================================================================
429//function : MakeColorPSA
430//purpose :
431//=======================================================================
432
433Handle(StepVisual_PresentationStyleAssignment) STEPConstruct_Styles::MakeColorPSA (const Handle(StepRepr_RepresentationItem) &/*item*/,
434 const Handle(StepVisual_Colour) &SurfCol,
435 const Handle(StepVisual_Colour) &CurveCol,
691711cd
IK
436 const Handle(StepVisual_Colour) &RenderCol,
437 const Standard_Real RenderTransp,
7fd59977 438 const Standard_Boolean isForNAUO) const
439{
440 Handle(StepVisual_PresentationStyleAssignment) PSA;
441 TColStd_SequenceOfTransient items;
442
443 // surface color
444 if ( ! SurfCol.IsNull() ) {
445 Handle(TCollection_HAsciiString) FASCName = new TCollection_HAsciiString ( "" );
446 Handle(StepVisual_FillAreaStyleColour) FASC = new StepVisual_FillAreaStyleColour;
447 FASC->Init ( FASCName, SurfCol );
448
449 StepVisual_FillStyleSelect FSS;
450 FSS.SetValue ( FASC );
451
452 Handle(StepVisual_HArray1OfFillStyleSelect) FASSs = new StepVisual_HArray1OfFillStyleSelect ( 1, 1 );
453 FASSs->SetValue ( 1, FSS );
454
455 Handle(TCollection_HAsciiString) FASName = new TCollection_HAsciiString ( "" );
456 Handle(StepVisual_FillAreaStyle) FAS = new StepVisual_FillAreaStyle;
457 FAS->Init ( FASName, FASSs );
458
459 Handle(StepVisual_SurfaceStyleFillArea) SSFA = new StepVisual_SurfaceStyleFillArea;
460 SSFA->Init ( FAS );
461
462 StepVisual_SurfaceStyleElementSelect SES;
463 SES.SetValue ( SSFA );
464
691711cd
IK
465 Handle(StepVisual_HArray1OfSurfaceStyleElementSelect) SSESs;
466 if (RenderTransp == 0.0) {
467 SSESs = new StepVisual_HArray1OfSurfaceStyleElementSelect ( 1, 1 );
468 } else {
469 Handle(StepVisual_SurfaceStyleTransparent) SST = new StepVisual_SurfaceStyleTransparent;
470 SST->Init(RenderTransp);
471 StepVisual_RenderingPropertiesSelect RPS;
472 RPS.SetValue(SST);
473 Handle(StepVisual_HArray1OfRenderingPropertiesSelect) HARP = new
474 StepVisual_HArray1OfRenderingPropertiesSelect (1, 1);
475 HARP->SetValue(1, RPS);
476 Handle(StepVisual_SurfaceStyleRenderingWithProperties) SSRWP = new StepVisual_SurfaceStyleRenderingWithProperties;
477
478 SSRWP->Init(StepVisual_ssmNormalShading, RenderCol, HARP);
479
480 StepVisual_SurfaceStyleElementSelect SESR;
481 SESR.SetValue (SSRWP);
482
483 SSESs = new StepVisual_HArray1OfSurfaceStyleElementSelect ( 1, 2 );
484 SSESs->SetValue ( 2, SESR );
485 }
7fd59977 486 SSESs->SetValue ( 1, SES );
691711cd 487
7fd59977 488 Handle(TCollection_HAsciiString) SSSName = new TCollection_HAsciiString ( "" );
489 Handle(StepVisual_SurfaceSideStyle) SSS = new StepVisual_SurfaceSideStyle;
490 SSS->Init ( SSSName, SSESs );
491
492 Handle(StepVisual_SurfaceStyleUsage) SSU = new StepVisual_SurfaceStyleUsage;
493 SSU->Init ( StepVisual_ssBoth, SSS );
494
495 items.Append ( SSU );
496 }
497
498 // curve color
499 if ( ! CurveCol.IsNull() ) {
500 Handle(TCollection_HAsciiString) fontName = new TCollection_HAsciiString("continuous");
501 Handle(StepVisual_DraughtingPreDefinedCurveFont) SDPDCF = new StepVisual_DraughtingPreDefinedCurveFont;
502 SDPDCF->Init(fontName);
503
504 Handle(StepBasic_MeasureValueMember) Val = new StepBasic_MeasureValueMember;
505 Val->SetReal ( 0.1 );
506 Val->SetName ( "POSITIVE_LENGTH_MEASURE");
507
508 StepVisual_CurveStyleFontSelect SCSFS;
509 SCSFS.SetValue(SDPDCF);
510
511 StepBasic_SizeSelect SSSelect;
512 SSSelect.SetValue(Val);
513
514 Handle(TCollection_HAsciiString) SCSName = new TCollection_HAsciiString ( "" );
515 Handle(StepVisual_CurveStyle) SCS = new StepVisual_CurveStyle;
516 SCS->Init(SCSName,SCSFS,SSSelect,CurveCol);
517
518 items.Append ( SCS );
519 }
520
521 if ( items.Length() <1 ) {
0797d9d3 522#ifdef OCCT_DEBUG
04232180 523 std::cout << "Error: no color is supplied" << std::endl;
7fd59977 524#endif
525 return PSA;
526 }
527
528 // general part
529 Handle(StepVisual_HArray1OfPresentationStyleSelect) PSSs =
530 new StepVisual_HArray1OfPresentationStyleSelect ( 1, items.Length() );
531 for ( Standard_Integer i=1; i <= items.Length(); i++ ) {
532 StepVisual_PresentationStyleSelect PSS;
533 PSS.SetValue ( items.Value(i) );
534 PSSs->SetValue ( i, PSS );
535 }
536 if (!isForNAUO)
537 PSA = new StepVisual_PresentationStyleAssignment;
538 else
539 PSA = new StepVisual_PresentationStyleByContext;
540 PSA->Init ( PSSs );
541
542 return PSA;
543}
544
545
546//=======================================================================
547//function : GetColorPSA
548//purpose :
549//=======================================================================
550
551Handle(StepVisual_PresentationStyleAssignment) STEPConstruct_Styles::GetColorPSA (const Handle(StepRepr_RepresentationItem) &item,
552 const Handle(StepVisual_Colour) &Col)
553{
554 // if this color already was processed, just use the same PSA, else create new and add it to map
555 Handle(StepVisual_PresentationStyleAssignment) PSA;
556 if ( myMapOfStyles.Contains(Col) ) {
557 PSA = Handle(StepVisual_PresentationStyleAssignment)::
558 DownCast(myMapOfStyles.FindFromKey(Col));
559 }
560 else {
691711cd 561 PSA = MakeColorPSA ( item, Col, Col, Col, 0.0 );
7fd59977 562 myMapOfStyles.Add(Col,PSA);
563 }
564 return PSA;
565}
566
567
568//=======================================================================
569//function : GetColors
570//purpose :
571//=======================================================================
572
573Standard_Boolean STEPConstruct_Styles::GetColors (const Handle(StepVisual_StyledItem) &style,
574 Handle(StepVisual_Colour) &SurfCol,
575 Handle(StepVisual_Colour) &BoundCol,
576 Handle(StepVisual_Colour) &CurveCol,
691711cd
IK
577 Handle(StepVisual_Colour) &RenderCol,
578 Standard_Real& RenderTransp,
7fd59977 579 Standard_Boolean& IsComponent) const
580{
581 SurfCol.Nullify();
582 BoundCol.Nullify();
583 CurveCol.Nullify();
691711cd 584 RenderCol.Nullify();
7fd59977 585
586 // parse on styles
587 for(Standard_Integer j=1; j<=style->NbStyles(); j++ ) {
588 Handle(StepVisual_PresentationStyleAssignment) PSA = style->StylesValue ( j );
0df4bbd6 589 if(PSA.IsNull() || PSA->Styles().IsNull()) continue;
7fd59977 590 IsComponent = Standard_True;
591
592 for(Standard_Integer k=1; k<=PSA->NbStyles(); k++ ) {
593 StepVisual_PresentationStyleSelect PSS = PSA->StylesValue(k);
594
595 // try surface_style_usage
596 Handle(StepVisual_SurfaceStyleUsage) SSU = PSS.SurfaceStyleUsage();
597 if( !SSU.IsNull() ) {
598 Handle(StepVisual_SurfaceSideStyle) SSS = SSU->Style();
599 for(Standard_Integer l=1; l<=SSS->NbStyles(); l++ ) {
600 StepVisual_SurfaceStyleElementSelect SSES = SSS->StylesValue(l);
601 // try fill color
602 Handle(StepVisual_SurfaceStyleFillArea) SSFA = SSES.SurfaceStyleFillArea();
603 if ( !SSFA.IsNull() ) {
604 Handle(StepVisual_FillAreaStyle) FAS = SSFA->FillArea();
53711314 605 if (FAS.IsNull())
606 continue;
7fd59977 607 for ( Standard_Integer m=1; m <= FAS->NbFillStyles(); m++ ) {
608 StepVisual_FillStyleSelect FSS = FAS->FillStylesValue ( m );
609 Handle(StepVisual_FillAreaStyleColour) FASC = FSS.FillAreaStyleColour();
610 if ( SurfCol.IsNull() || SSU->Side() != StepVisual_ssNegative ) //abv 30 Mar 00: trj3_s1-pe.stp
611 SurfCol = FASC->FillColour();
612 }
613 continue;
614 }
615 // try boundary color
616 Handle(StepVisual_SurfaceStyleBoundary) SSB = SSES.SurfaceStyleBoundary();
617 if(!SSB.IsNull()) {
618 Handle(StepVisual_CurveStyle) CS = SSB->StyleOfBoundary();
619 if ( ! CS.IsNull() ) BoundCol = CS->CurveColour();
620 continue;
621 }
691711cd
IK
622 // try rendering color and transparency
623 Handle(StepVisual_SurfaceStyleRendering) SSR = SSES.SurfaceStyleRendering();
624 if (!SSR.IsNull()) {
625 RenderCol = SSR->SurfaceColour();
626 RenderTransp = 0.0;
627 Handle(StepVisual_SurfaceStyleRenderingWithProperties) SSRWP =
628 Handle(StepVisual_SurfaceStyleRenderingWithProperties)::DownCast(SSR);
629 if (!SSRWP.IsNull()) {
630 Handle(StepVisual_HArray1OfRenderingPropertiesSelect) HARP = SSRWP->Properties();
631 if (!HARP.IsNull())
632 {
633 for (Standard_Integer aPropIndex = 1; aPropIndex <= HARP->Length(); ++aPropIndex) {
634 Handle(StepVisual_SurfaceStyleTransparent) SST = HARP->Value(aPropIndex).SurfaceStyleTransparent();
635 if (!SST.IsNull()) {
636 RenderTransp = SST->Transparency();
637 }
638 }
639 }
640 }
641 }
642
7fd59977 643 }
644 continue;
645 }
646
647 // try curve_style
648 Handle(StepVisual_CurveStyle) CS = PSS.CurveStyle();
649 if ( ! CS.IsNull() ) CurveCol = CS->CurveColour();
650 }
651 }
691711cd 652 return ! SurfCol.IsNull() || ! BoundCol.IsNull() || ! CurveCol.IsNull() || ! RenderCol.IsNull();
7fd59977 653}
654
655
656//=======================================================================
657//function : EncodeColor
658//purpose :
659//=======================================================================
660
661Handle(StepVisual_Colour) STEPConstruct_Styles::EncodeColor(const Quantity_Color &C)
662{
663 // detect if color corresponds to one of pre-defined colors
664 Standard_CString cName = 0;
665 if ( C == Quantity_Color(Quantity_NOC_GREEN) ) cName = "green";
666 else if ( C == Quantity_Color(Quantity_NOC_RED) ) cName = "red";
667 else if ( C == Quantity_Color(Quantity_NOC_BLUE1) ) cName = "blue";
668 else if ( C == Quantity_Color(Quantity_NOC_YELLOW) ) cName = "yellow";
669 else if ( C == Quantity_Color(Quantity_NOC_MAGENTA1) ) cName = "magenta";
670 else if ( C == Quantity_Color(Quantity_NOC_CYAN1) ) cName = "cyan";
671 else if ( C == Quantity_Color(Quantity_NOC_BLACK) ) cName = "black";
672 else if ( C == Quantity_Color(Quantity_NOC_WHITE) ) cName = "white";
673
674 if ( cName ) {
675 Handle(StepVisual_DraughtingPreDefinedColour) ColPr = new StepVisual_DraughtingPreDefinedColour;
676 Handle(StepVisual_PreDefinedItem) preDef = new StepVisual_PreDefinedItem;
677 preDef->Init(new TCollection_HAsciiString(cName));
678 ColPr->SetPreDefinedItem(preDef);
679 return ColPr;
680 }
681 else {
682 Handle(TCollection_HAsciiString) ColName = new TCollection_HAsciiString ( "" );
683 Handle(StepVisual_ColourRgb) ColRGB = new StepVisual_ColourRgb;
ba00aab7 684 NCollection_Vec3<Standard_Real> aColor_sRGB;
685 C.Values (aColor_sRGB.r(), aColor_sRGB.g(), aColor_sRGB.b(), Quantity_TOC_sRGB);
686 ColRGB->Init ( ColName, aColor_sRGB.r(), aColor_sRGB.g(), aColor_sRGB.b() );
7fd59977 687 return ColRGB;
688 }
689}
690
691
692//=======================================================================
693//function : EncodeColor
694//purpose :
695//=======================================================================
696
697Handle(StepVisual_Colour) STEPConstruct_Styles::EncodeColor
698 (const Quantity_Color &C,
699 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
700 STEPConstruct_DataMapOfPointTransient &ColRGBs)
701{
702 // detect if color corresponds to one of pre-defined colors
703 Standard_CString cName = 0;
704 if ( C == Quantity_Color(Quantity_NOC_GREEN) ) cName = "green";
705 else if ( C == Quantity_Color(Quantity_NOC_RED) ) cName = "red";
706 else if ( C == Quantity_Color(Quantity_NOC_BLUE1) ) cName = "blue";
707 else if ( C == Quantity_Color(Quantity_NOC_YELLOW) ) cName = "yellow";
708 else if ( C == Quantity_Color(Quantity_NOC_MAGENTA1) ) cName = "magenta";
709 else if ( C == Quantity_Color(Quantity_NOC_CYAN1) ) cName = "cyan";
710 else if ( C == Quantity_Color(Quantity_NOC_BLACK) ) cName = "black";
711 else if ( C == Quantity_Color(Quantity_NOC_WHITE) ) cName = "white";
712
713 if ( cName ) {
714 Handle(StepVisual_DraughtingPreDefinedColour) ColPr;
715 TCollection_AsciiString aName(cName);
716 if(DPDCs.IsBound(aName)) {
717 ColPr = Handle(StepVisual_DraughtingPreDefinedColour)::DownCast(DPDCs.Find(aName));
718 if(!ColPr.IsNull()) return ColPr;
719 }
720 ColPr = new StepVisual_DraughtingPreDefinedColour;
721 Handle(StepVisual_PreDefinedItem) preDef = new StepVisual_PreDefinedItem;
722 preDef->Init(new TCollection_HAsciiString(cName));
723 ColPr->SetPreDefinedItem(preDef);
724 DPDCs.Bind(aName,ColPr);
725 return ColPr;
726 }
727 else {
728 Handle(StepVisual_ColourRgb) ColRGB;
ba00aab7 729 gp_Pnt P;
730 C.Values (P.ChangeCoord().ChangeData()[0],
731 P.ChangeCoord().ChangeData()[1],
732 P.ChangeCoord().ChangeData()[2],
733 Quantity_TOC_sRGB);
7fd59977 734 if(ColRGBs.IsBound(P)) {
735 ColRGB = Handle(StepVisual_ColourRgb)::DownCast(ColRGBs.Find(P));
736 if(!ColRGB.IsNull()) return ColRGB;
737 }
738 Handle(TCollection_HAsciiString) ColName = new TCollection_HAsciiString ( "" );
739 ColRGB = new StepVisual_ColourRgb;
ba00aab7 740 ColRGB->Init ( ColName, P.Coord (1), P.Coord (2), P.Coord (3) );
7fd59977 741 ColRGBs.Bind(P,ColRGB);
742 return ColRGB;
743 }
744}
745
746
747//=======================================================================
748//function : DecodeColor
749//purpose :
750//=======================================================================
751
752Standard_Boolean STEPConstruct_Styles::DecodeColor (const Handle(StepVisual_Colour) &Colour, Quantity_Color &Col)
753{
754 if ( Colour->IsKind (STANDARD_TYPE(StepVisual_ColourRgb)) ) {
755 Handle(StepVisual_ColourRgb) rgb = Handle(StepVisual_ColourRgb)::DownCast ( Colour );
756 if( rgb->Red()>1. || rgb->Green()>1. || rgb->Blue()>1. ) {
757 Standard_Real norm = rgb->Red();
758 if(norm<rgb->Green()) norm = rgb->Green();
759 if(norm<rgb->Blue()) norm = rgb->Blue();
760 Col.SetValues(rgb->Red()/norm, rgb->Green()/norm,
ba00aab7 761 rgb->Blue()/norm, Quantity_TOC_sRGB);
7fd59977 762 }
763 else
ba00aab7 764 Col.SetValues(rgb->Red(), rgb->Green(), rgb->Blue(), Quantity_TOC_sRGB);
7fd59977 765 return Standard_True;
766 }
767 else if ( Colour->IsKind (STANDARD_TYPE(StepVisual_PreDefinedColour)) ) {
768 Handle(StepVisual_PreDefinedColour) pdc =
769 Handle(StepVisual_PreDefinedColour)::DownCast ( Colour );
770 Handle(StepVisual_PreDefinedItem) pdi = pdc->GetPreDefinedItem();
771 const TCollection_AsciiString name = pdi->Name()->String();
772 if ( name.IsEqual ( "red" ) ) Col.SetValues ( Quantity_NOC_RED );
773 else if ( name.IsEqual ( "green" ) ) Col.SetValues ( Quantity_NOC_GREEN );
774 else if ( name.IsEqual ( "blue" ) ) Col.SetValues ( Quantity_NOC_BLUE1 );
775 else if ( name.IsEqual ( "yellow" ) ) Col.SetValues ( Quantity_NOC_YELLOW );
776 else if ( name.IsEqual ( "magenta" ) ) Col.SetValues ( Quantity_NOC_MAGENTA1 );
777 else if ( name.IsEqual ( "cyan" ) ) Col.SetValues ( Quantity_NOC_CYAN1 );
778 else if ( name.IsEqual ( "black" ) ) Col.SetValues ( Quantity_NOC_BLACK );
779 else if ( name.IsEqual ( "white" ) ) Col.SetValues ( Quantity_NOC_WHITE );
780 else {
0797d9d3 781#ifdef OCCT_DEBUG
04232180 782 std::cout << "Error: color name \"" << name << "\" is not recognized" << std::endl;
7fd59977 783#endif
784 return Standard_False;
785 }
786 return Standard_True;
787 }
788 return Standard_False;
789}
790