1 // Created on: 1999-09-10
2 // Created by: Andrey BETENEV
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <APIHeaderSection_MakeHeader.hxx>
19 #include <Interface_EntityIterator.hxx>
20 #include <Interface_Static.hxx>
21 #include <Quantity_Color.hxx>
22 #include <StepBasic_MeasureValueMember.hxx>
23 #include <STEPConstruct.hxx>
24 #include <STEPConstruct_Styles.hxx>
25 #include <StepData_StepModel.hxx>
26 #include <StepGeom_GeometricRepresentationItem.hxx>
27 #include <StepRepr_ItemDefinedTransformation.hxx>
28 #include <StepRepr_ProductDefinitionShape.hxx>
29 #include <StepRepr_RepresentationContext.hxx>
30 #include <StepRepr_RepresentationItem.hxx>
31 #include <StepRepr_RepresentationRelationshipWithTransformation.hxx>
32 #include <StepRepr_ShapeRepresentationRelationship.hxx>
33 #include <StepRepr_Transformation.hxx>
34 #include <StepShape_ContextDependentShapeRepresentation.hxx>
35 #include <StepShape_ShapeDefinitionRepresentation.hxx>
36 #include <StepShape_ShapeRepresentation.hxx>
37 #include <StepVisual_ColourRgb.hxx>
38 #include <StepVisual_CurveStyle.hxx>
39 #include <StepVisual_DraughtingModel.hxx>
40 #include <StepVisual_DraughtingPreDefinedColour.hxx>
41 #include <StepVisual_DraughtingPreDefinedCurveFont.hxx>
42 #include <StepVisual_FillAreaStyle.hxx>
43 #include <StepVisual_FillAreaStyleColour.hxx>
44 #include <StepVisual_FillStyleSelect.hxx>
45 #include <StepVisual_HArray1OfFillStyleSelect.hxx>
46 #include <StepVisual_Invisibility.hxx>
47 #include <StepVisual_InvisibleItem.hxx>
48 #include <StepVisual_MechanicalDesignGeometricPresentationRepresentation.hxx>
49 #include <StepVisual_OverRidingStyledItem.hxx>
50 #include <StepVisual_PreDefinedColour.hxx>
51 #include <StepVisual_PreDefinedItem.hxx>
52 #include <StepVisual_PresentationStyleAssignment.hxx>
53 #include <StepVisual_PresentationStyleByContext.hxx>
54 #include <StepVisual_PresentationStyleSelect.hxx>
55 #include <StepVisual_StyledItem.hxx>
56 #include <StepVisual_SurfaceSideStyle.hxx>
57 #include <StepVisual_SurfaceStyleBoundary.hxx>
58 #include <StepVisual_SurfaceStyleElementSelect.hxx>
59 #include <StepVisual_SurfaceStyleFillArea.hxx>
60 #include <StepVisual_SurfaceStyleRenderingWithProperties.hxx>
61 #include <StepVisual_RenderingPropertiesSelect.hxx>
62 #include <StepVisual_SurfaceStyleTransparent.hxx>
63 #include <StepVisual_SurfaceStyleUsage.hxx>
64 #include <TCollection_HAsciiString.hxx>
65 #include <TColStd_HSequenceOfTransient.hxx>
66 #include <TransferBRep.hxx>
67 #include <TransferBRep_ShapeMapper.hxx>
68 #include <XSControl_TransferReader.hxx>
69 #include <XSControl_TransferWriter.hxx>
70 #include <XSControl_WorkSession.hxx>
71 #include <StepVisual_ContextDependentOverRidingStyledItem.hxx>
72 #include <StepShape_ShapeRepresentation.hxx>
74 //=======================================================================
75 //function : STEPConstruct_Styles
77 //=======================================================================
78 STEPConstruct_Styles::STEPConstruct_Styles ()
83 //=======================================================================
84 //function : STEPConstruct_Styles
86 //=======================================================================
88 STEPConstruct_Styles::STEPConstruct_Styles (const Handle(XSControl_WorkSession) &WS)
89 : STEPConstruct_Tool ( WS )
94 //=======================================================================
97 //=======================================================================
99 Standard_Boolean STEPConstruct_Styles::Init (const Handle(XSControl_WorkSession) &WS)
101 myMapOfStyles.Clear();
108 //=======================================================================
109 //function : NbStyles
111 //=======================================================================
113 Standard_Integer STEPConstruct_Styles::NbStyles () const
115 return myStyles.Extent();
119 //=======================================================================
122 //=======================================================================
124 Handle(StepVisual_StyledItem) STEPConstruct_Styles::Style (const Standard_Integer i) const
126 return Handle(StepVisual_StyledItem)::DownCast ( myStyles.FindKey(i) );
129 //=======================================================================
130 //function : NbRootStyles
132 //=======================================================================
134 Standard_Integer STEPConstruct_Styles::NbRootStyles () const
136 return myRootStyles.Extent();
139 //=======================================================================
140 //function : RootStyle
142 //=======================================================================
144 Handle(StepVisual_StyledItem) STEPConstruct_Styles::RootStyle (const Standard_Integer i) const
146 return Handle(StepVisual_StyledItem)::DownCast ( myRootStyles.FindKey(i) );
150 //=======================================================================
151 //function : ClearStyles
153 //=======================================================================
155 void STEPConstruct_Styles::ClearStyles ()
159 myRootStyles.Clear();
163 //=======================================================================
164 //function : AddStyle
166 //=======================================================================
168 void STEPConstruct_Styles::AddStyle (const Handle(StepVisual_StyledItem) &style)
170 myStyles.Add ( style );
174 //=======================================================================
175 //function : AddStyle
177 //=======================================================================
179 Handle(StepVisual_StyledItem) STEPConstruct_Styles::AddStyle (const Handle(StepRepr_RepresentationItem) &item,
180 const Handle(StepVisual_PresentationStyleAssignment) &PSA,
181 const Handle(StepVisual_StyledItem) &Override)
183 Handle(StepVisual_StyledItem) Style;
185 Handle(StepVisual_HArray1OfPresentationStyleAssignment) Styles =
186 new StepVisual_HArray1OfPresentationStyleAssignment ( 1, 1 );
187 Styles->SetValue ( 1, PSA );
189 if ( Override.IsNull() ) {
190 Handle(TCollection_HAsciiString) StyName = new TCollection_HAsciiString ( "color" );
191 Style = new StepVisual_StyledItem;
192 Style->Init ( StyName, Styles, item );
195 Handle(TCollection_HAsciiString) StyName = new TCollection_HAsciiString ( "overriding color" );
196 Handle(StepVisual_OverRidingStyledItem) OStyle = new StepVisual_OverRidingStyledItem;
197 OStyle->Init ( StyName, Styles, item, Override );
201 myStyles.Add ( Style );
209 //=======================================================================
210 //function : AddStyle
212 //=======================================================================
214 Handle(StepVisual_StyledItem) STEPConstruct_Styles::AddStyle (const TopoDS_Shape &Shape,
215 const Handle(StepVisual_PresentationStyleAssignment) &PSA,
216 const Handle(StepVisual_StyledItem) &Override)
218 Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity ( FinderProcess(), Shape );
219 Handle(StepVisual_StyledItem) Style;
220 if ( ! item.IsNull() ) Style = AddStyle ( item, PSA, Override );
225 //=======================================================================
226 //function : CreateMDGPR
228 //=======================================================================
230 Standard_Boolean STEPConstruct_Styles::CreateMDGPR (const Handle(StepRepr_RepresentationContext) &Context,
231 Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)& Repr,
232 Handle(StepData_StepModel)& theStepModel)
234 if ( myStyles.Extent() <1 ) return Standard_False;
236 // create MECHANICAL_DESIGN_GEOMETRIC_PRESENTATION_REPRESENTATION
237 Handle(StepRepr_HArray1OfRepresentationItem) elems =
238 new StepRepr_HArray1OfRepresentationItem ( 1, myStyles.Extent() );
239 for ( Standard_Integer i=1; i <= myStyles.Extent(); i++ )
240 elems->SetValue ( i, Handle(StepRepr_RepresentationItem)::DownCast ( myStyles.FindKey(i) ) );
242 Repr = new StepVisual_MechanicalDesignGeometricPresentationRepresentation;
243 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
244 Repr->Init ( ReprName, elems, Context );
246 // record Repr in order to have it written to the file
247 // Model()->AddWithRefs ( Repr ); add into the model upper
249 // for AP203, add subschema name
250 if ( theStepModel->InternalParameters.WriteSchema == 3 ) {
251 APIHeaderSection_MakeHeader mkHdr ( Handle(StepData_StepModel)::DownCast ( Model() ) );
252 Handle(TCollection_HAsciiString) subSchema =
253 new TCollection_HAsciiString ( "SHAPE_APPEARANCE_LAYER_MIM" );
254 mkHdr.AddSchemaIdentifier ( subSchema );
257 return Standard_True;
261 //=======================================================================
262 //function : CreateNAUOSRD
264 //=======================================================================
266 Standard_Boolean STEPConstruct_Styles::CreateNAUOSRD (const Handle(StepRepr_RepresentationContext) &Context,
267 const Handle(StepShape_ContextDependentShapeRepresentation)& CDSR,
268 const Handle(StepRepr_ProductDefinitionShape)& initPDS)
270 Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
271 new StepShape_ShapeDefinitionRepresentation;
272 Handle(StepShape_ShapeRepresentation) aSR =
273 new StepShape_ShapeRepresentation;
274 Handle(TCollection_HAsciiString) ReprName = new TCollection_HAsciiString ( "" );
275 // element for axis 2 placement
276 Handle(StepRepr_HArray1OfRepresentationItem) elems =
277 new StepRepr_HArray1OfRepresentationItem ( 1, 1 );
279 Handle(StepRepr_ProductDefinitionShape) aPDS;
280 if ( initPDS.IsNull() )
281 aPDS = CDSR->RepresentedProductRelation();
283 aPDS = initPDS; // for SHUO
284 Handle(StepRepr_ShapeRepresentationRelationship) aRepRelationShip = CDSR->RepresentationRelation();
285 Handle(StepRepr_RepresentationRelationshipWithTransformation) aRRwTRSF =
286 Handle(StepRepr_RepresentationRelationshipWithTransformation)::DownCast(aRepRelationShip);
287 StepRepr_Transformation SetReprTRSF;
288 if (!aRRwTRSF.IsNull())
289 SetReprTRSF = aRRwTRSF->TransformationOperator();
291 return Standard_False;
292 // take Item defined transformation
293 Handle(StepRepr_ItemDefinedTransformation) anItDT = SetReprTRSF.ItemDefinedTransformation();
294 elems->SetValue( 1, anItDT->TransformItem2() );
295 // init Shape representation.
296 aSR->Init ( ReprName, elems, Context );
297 // register reference between PresentationStyleByContext and ShapeRepresentation
298 for (Standard_Integer psbci = 1; psbci <= myPSA.Length(); psbci++) {
299 Handle(StepVisual_PresentationStyleByContext) PSA =
300 Handle(StepVisual_PresentationStyleByContext)::DownCast(myPSA.Value(psbci));
303 // register the reference
304 StepVisual_StyleContextSelect aStyleCntxSlct;
305 aStyleCntxSlct.SetValue( aSR );
306 PSA->SetStyleContext( aStyleCntxSlct );
309 StepRepr_RepresentedDefinition aPDSselect;
310 aPDSselect.SetValue(aPDS);
311 aSDR->Init( aPDSselect, aSR );
312 Model()->AddWithRefs ( aSDR );
314 return Standard_True;
318 //=======================================================================
319 //function : FindContext
321 //=======================================================================
323 Handle(StepRepr_RepresentationContext) STEPConstruct_Styles::FindContext (const TopoDS_Shape &Shape) const
325 // find context of items
326 Handle(StepRepr_RepresentationContext) Context;
327 Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FinderProcess(), Shape );
328 Handle(StepShape_ShapeRepresentation) sr;
329 if ( FinderProcess()->FindTypedTransient (mapper,STANDARD_TYPE(StepShape_ShapeRepresentation), sr) ) {
331 // std::cout << "Context of " << Shape.TShape()->DynamicType()->Name() << ": SR found: " << sr->DynamicType()->Name() << std::endl;
333 Context = sr->ContextOfItems();
336 Handle(StepGeom_GeometricRepresentationItem) item;
337 if ( FinderProcess()->FindTypedTransient (mapper,STANDARD_TYPE(StepGeom_GeometricRepresentationItem), item) ) {
339 // std::cout << "Context of " << Shape.TShape()->DynamicType()->Name() << ": GeomRepItem found: " << item->DynamicType()->Name() << std::endl;
341 Interface_EntityIterator subs = Graph().Sharings(item);
342 for (subs.Start(); Context.IsNull() && subs.More(); subs.Next()) {
344 // std::cout << "Parsing back refs: found " << subs.Value()->DynamicType()->Name() << std::endl;
346 if ( ! subs.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation)) ) continue;
347 sr = Handle(StepShape_ShapeRepresentation)::DownCast ( subs.Value() );
348 Context = sr->ContextOfItems();
353 if ( Context.IsNull() ) {
354 std::cout << Shape.TShape()->DynamicType()->Name() << ": Cannot find context" << std::endl;
362 //=======================================================================
363 //function : LoadStyles
365 //=======================================================================
367 Standard_Boolean STEPConstruct_Styles::LoadStyles ()
371 myRootStyles.Clear();
373 // find all MDGPRs and DMs and collect all defined styles in myStyles
374 Handle(Interface_InterfaceModel) model = Model();
375 Standard_Integer nb = model->NbEntities();
376 Handle(Standard_Type) tMDGPR = STANDARD_TYPE(StepVisual_MechanicalDesignGeometricPresentationRepresentation);
377 Handle(Standard_Type) tDM = STANDARD_TYPE(StepVisual_DraughtingModel);
378 Handle(Standard_Type) tSI = STANDARD_TYPE(StepVisual_StyledItem);
379 Handle(Standard_Type) tSR = STANDARD_TYPE(StepShape_ShapeRepresentation);
380 for (Standard_Integer i = 1; i <= nb; i ++)
382 Handle(Standard_Transient) enti = model->Value(i);
383 if ( enti->DynamicType() == tMDGPR || enti->DynamicType() == tDM )
385 Handle(StepRepr_Representation) container = Handle(StepRepr_Representation)::DownCast ( enti );
387 Standard_Integer nbi = container->NbItems();
388 for ( Standard_Integer j=1; j <= nbi; j++ )
390 Handle(StepVisual_StyledItem) style =
391 Handle(StepVisual_StyledItem)::DownCast ( container->ItemsValue(j) );
392 if ( style.IsNull() ) continue;
393 auto anItem = style->ItemAP242 ().Value ();
394 if (!anItem.IsNull() && anItem->IsKind(tSR))
396 myRootStyles.Add (style);
400 myStyles.Add (style);
404 else if (enti->IsKind (STANDARD_TYPE(StepVisual_StyledItem)))
406 Handle(StepVisual_StyledItem) aStyledItem = Handle(StepVisual_StyledItem)::DownCast (enti);
407 auto anItem = aStyledItem->ItemAP242 ().Value ();
408 if (!anItem.IsNull() && anItem->IsKind(tSR) && !myRootStyles.Contains (aStyledItem))
410 myRootStyles.Add (aStyledItem);
412 else if (!myStyles.Contains (aStyledItem))
414 myStyles.Add (aStyledItem);
418 return !myStyles.IsEmpty();
422 //=======================================================================
423 //function : LoadInvisStyles
425 //=======================================================================
427 Standard_Boolean STEPConstruct_Styles::LoadInvisStyles (Handle(TColStd_HSequenceOfTransient)& theInvStyles) const
429 Handle(Interface_InterfaceModel) model = Model();
430 Standard_Integer nb = model->NbEntities();
431 Handle(Standard_Type) tInvisibility = STANDARD_TYPE(StepVisual_Invisibility);
432 // search for invisibility
433 for (Standard_Integer i = 1; i <= nb; i ++) {
434 Handle(Standard_Transient) enti = model->Value(i);
435 if ( enti->DynamicType() != tInvisibility )
437 // search for styled items
438 Handle(StepVisual_Invisibility) container = Handle(StepVisual_Invisibility)::DownCast ( enti );
439 Standard_Integer nbi = container->NbInvisibleItems();
440 for ( Standard_Integer j=1; j <= nbi; j++ ) {
441 StepVisual_InvisibleItem anInvItem = container->InvisibleItemsValue(j);
442 Handle(StepVisual_StyledItem) style = anInvItem.StyledItem();
443 if ( style.IsNull() )
445 // collect the invisible styled items
446 if ( theInvStyles.IsNull() )
447 theInvStyles = new TColStd_HSequenceOfTransient;
448 theInvStyles->Append( style );
451 return ( !theInvStyles.IsNull() && (theInvStyles->Length() > 0) );
455 //=======================================================================
456 //function : MakeColorPSA
458 //=======================================================================
460 Handle(StepVisual_PresentationStyleAssignment) STEPConstruct_Styles::MakeColorPSA (const Handle(StepRepr_RepresentationItem) &/*item*/,
461 const Handle(StepVisual_Colour) &SurfCol,
462 const Handle(StepVisual_Colour) &CurveCol,
463 const Handle(StepVisual_Colour) &RenderCol,
464 const Standard_Real RenderTransp,
465 const Standard_Boolean isForNAUO) const
467 Handle(StepVisual_PresentationStyleAssignment) PSA;
468 TColStd_SequenceOfTransient items;
471 if ( ! SurfCol.IsNull() ) {
472 Handle(TCollection_HAsciiString) FASCName = new TCollection_HAsciiString ( "" );
473 Handle(StepVisual_FillAreaStyleColour) FASC = new StepVisual_FillAreaStyleColour;
474 FASC->Init ( FASCName, SurfCol );
476 StepVisual_FillStyleSelect FSS;
477 FSS.SetValue ( FASC );
479 Handle(StepVisual_HArray1OfFillStyleSelect) FASSs = new StepVisual_HArray1OfFillStyleSelect ( 1, 1 );
480 FASSs->SetValue ( 1, FSS );
482 Handle(TCollection_HAsciiString) FASName = new TCollection_HAsciiString ( "" );
483 Handle(StepVisual_FillAreaStyle) FAS = new StepVisual_FillAreaStyle;
484 FAS->Init ( FASName, FASSs );
486 Handle(StepVisual_SurfaceStyleFillArea) SSFA = new StepVisual_SurfaceStyleFillArea;
489 StepVisual_SurfaceStyleElementSelect SES;
490 SES.SetValue ( SSFA );
492 Handle(StepVisual_HArray1OfSurfaceStyleElementSelect) SSESs;
493 if (RenderTransp == 0.0) {
494 SSESs = new StepVisual_HArray1OfSurfaceStyleElementSelect ( 1, 1 );
496 Handle(StepVisual_SurfaceStyleTransparent) SST = new StepVisual_SurfaceStyleTransparent;
497 SST->Init(RenderTransp);
498 StepVisual_RenderingPropertiesSelect RPS;
500 Handle(StepVisual_HArray1OfRenderingPropertiesSelect) HARP = new
501 StepVisual_HArray1OfRenderingPropertiesSelect (1, 1);
502 HARP->SetValue(1, RPS);
503 Handle(StepVisual_SurfaceStyleRenderingWithProperties) SSRWP = new StepVisual_SurfaceStyleRenderingWithProperties;
505 SSRWP->Init(StepVisual_ssmNormalShading, RenderCol, HARP);
507 StepVisual_SurfaceStyleElementSelect SESR;
508 SESR.SetValue (SSRWP);
510 SSESs = new StepVisual_HArray1OfSurfaceStyleElementSelect ( 1, 2 );
511 SSESs->SetValue ( 2, SESR );
513 SSESs->SetValue ( 1, SES );
515 Handle(TCollection_HAsciiString) SSSName = new TCollection_HAsciiString ( "" );
516 Handle(StepVisual_SurfaceSideStyle) SSS = new StepVisual_SurfaceSideStyle;
517 SSS->Init ( SSSName, SSESs );
519 Handle(StepVisual_SurfaceStyleUsage) SSU = new StepVisual_SurfaceStyleUsage;
520 SSU->Init ( StepVisual_ssBoth, SSS );
522 items.Append ( SSU );
526 if ( ! CurveCol.IsNull() ) {
527 Handle(TCollection_HAsciiString) fontName = new TCollection_HAsciiString("continuous");
528 Handle(StepVisual_DraughtingPreDefinedCurveFont) SDPDCF = new StepVisual_DraughtingPreDefinedCurveFont;
529 SDPDCF->Init(fontName);
531 Handle(StepBasic_MeasureValueMember) Val = new StepBasic_MeasureValueMember;
532 Val->SetReal ( 0.1 );
533 Val->SetName ( "POSITIVE_LENGTH_MEASURE");
535 StepVisual_CurveStyleFontSelect SCSFS;
536 SCSFS.SetValue(SDPDCF);
538 StepBasic_SizeSelect SSSelect;
539 SSSelect.SetValue(Val);
541 Handle(TCollection_HAsciiString) SCSName = new TCollection_HAsciiString ( "" );
542 Handle(StepVisual_CurveStyle) SCS = new StepVisual_CurveStyle;
543 SCS->Init(SCSName,SCSFS,SSSelect,CurveCol);
545 items.Append ( SCS );
548 if ( items.Length() <1 ) {
550 std::cout << "Error: no color is supplied" << std::endl;
556 Handle(StepVisual_HArray1OfPresentationStyleSelect) PSSs =
557 new StepVisual_HArray1OfPresentationStyleSelect ( 1, items.Length() );
558 for ( Standard_Integer i=1; i <= items.Length(); i++ ) {
559 StepVisual_PresentationStyleSelect PSS;
560 PSS.SetValue ( items.Value(i) );
561 PSSs->SetValue ( i, PSS );
564 PSA = new StepVisual_PresentationStyleAssignment;
566 PSA = new StepVisual_PresentationStyleByContext;
573 //=======================================================================
574 //function : GetColorPSA
576 //=======================================================================
578 Handle(StepVisual_PresentationStyleAssignment) STEPConstruct_Styles::GetColorPSA (const Handle(StepRepr_RepresentationItem) &item,
579 const Handle(StepVisual_Colour) &Col)
581 // if this color already was processed, just use the same PSA, else create new and add it to map
582 Handle(StepVisual_PresentationStyleAssignment) PSA;
583 if ( myMapOfStyles.Contains(Col) ) {
584 PSA = Handle(StepVisual_PresentationStyleAssignment)::
585 DownCast(myMapOfStyles.FindFromKey(Col));
588 PSA = MakeColorPSA ( item, Col, Col, Col, 0.0 );
589 myMapOfStyles.Add(Col,PSA);
595 //=======================================================================
596 //function : GetColors
598 //=======================================================================
600 Standard_Boolean STEPConstruct_Styles::GetColors (const Handle(StepVisual_StyledItem) &style,
601 Handle(StepVisual_Colour) &SurfCol,
602 Handle(StepVisual_Colour) &BoundCol,
603 Handle(StepVisual_Colour) &CurveCol,
604 Handle(StepVisual_Colour) &RenderCol,
605 Standard_Real& RenderTransp,
606 Standard_Boolean& IsComponent) const
614 for(Standard_Integer j=1; j<=style->NbStyles(); j++ ) {
615 Handle(StepVisual_PresentationStyleAssignment) PSA = style->StylesValue ( j );
616 if(PSA.IsNull() || PSA->Styles().IsNull()) continue;
617 IsComponent = Standard_True;
619 for(Standard_Integer k=1; k<=PSA->NbStyles(); k++ ) {
620 StepVisual_PresentationStyleSelect PSS = PSA->StylesValue(k);
622 // try surface_style_usage
623 Handle(StepVisual_SurfaceStyleUsage) SSU = PSS.SurfaceStyleUsage();
624 if( !SSU.IsNull() ) {
625 Handle(StepVisual_SurfaceSideStyle) SSS = SSU->Style();
626 for(Standard_Integer l=1; l<=SSS->NbStyles(); l++ ) {
627 StepVisual_SurfaceStyleElementSelect SSES = SSS->StylesValue(l);
629 Handle(StepVisual_SurfaceStyleFillArea) SSFA = SSES.SurfaceStyleFillArea();
630 if ( !SSFA.IsNull() ) {
631 Handle(StepVisual_FillAreaStyle) FAS = SSFA->FillArea();
634 for ( Standard_Integer m=1; m <= FAS->NbFillStyles(); m++ ) {
635 StepVisual_FillStyleSelect FSS = FAS->FillStylesValue ( m );
636 Handle(StepVisual_FillAreaStyleColour) FASC = FSS.FillAreaStyleColour();
637 if ( SurfCol.IsNull() || SSU->Side() != StepVisual_ssNegative ) //abv 30 Mar 00: trj3_s1-pe.stp
638 SurfCol = FASC->FillColour();
642 // try boundary color
643 Handle(StepVisual_SurfaceStyleBoundary) SSB = SSES.SurfaceStyleBoundary();
645 Handle(StepVisual_CurveStyle) CS = SSB->StyleOfBoundary();
646 if ( ! CS.IsNull() ) BoundCol = CS->CurveColour();
649 // try rendering color and transparency
650 Handle(StepVisual_SurfaceStyleRendering) SSR = SSES.SurfaceStyleRendering();
652 RenderCol = SSR->SurfaceColour();
654 Handle(StepVisual_SurfaceStyleRenderingWithProperties) SSRWP =
655 Handle(StepVisual_SurfaceStyleRenderingWithProperties)::DownCast(SSR);
656 if (!SSRWP.IsNull()) {
657 Handle(StepVisual_HArray1OfRenderingPropertiesSelect) HARP = SSRWP->Properties();
660 for (Standard_Integer aPropIndex = 1; aPropIndex <= HARP->Length(); ++aPropIndex) {
661 Handle(StepVisual_SurfaceStyleTransparent) SST = HARP->Value(aPropIndex).SurfaceStyleTransparent();
663 RenderTransp = SST->Transparency();
675 Handle(StepVisual_CurveStyle) CS = PSS.CurveStyle();
676 if ( ! CS.IsNull() ) CurveCol = CS->CurveColour();
679 return ! SurfCol.IsNull() || ! BoundCol.IsNull() || ! CurveCol.IsNull() || ! RenderCol.IsNull();
683 //=======================================================================
684 //function : EncodeColor
686 //=======================================================================
688 Handle(StepVisual_Colour) STEPConstruct_Styles::EncodeColor(const Quantity_Color &C)
690 // detect if color corresponds to one of pre-defined colors
691 Standard_CString cName = 0;
692 if ( C == Quantity_Color(Quantity_NOC_GREEN) ) cName = "green";
693 else if ( C == Quantity_Color(Quantity_NOC_RED) ) cName = "red";
694 else if ( C == Quantity_Color(Quantity_NOC_BLUE1) ) cName = "blue";
695 else if ( C == Quantity_Color(Quantity_NOC_YELLOW) ) cName = "yellow";
696 else if ( C == Quantity_Color(Quantity_NOC_MAGENTA1) ) cName = "magenta";
697 else if ( C == Quantity_Color(Quantity_NOC_CYAN1) ) cName = "cyan";
698 else if ( C == Quantity_Color(Quantity_NOC_BLACK) ) cName = "black";
699 else if ( C == Quantity_Color(Quantity_NOC_WHITE) ) cName = "white";
702 Handle(StepVisual_DraughtingPreDefinedColour) ColPr = new StepVisual_DraughtingPreDefinedColour;
703 Handle(StepVisual_PreDefinedItem) preDef = new StepVisual_PreDefinedItem;
704 preDef->Init(new TCollection_HAsciiString(cName));
705 ColPr->SetPreDefinedItem(preDef);
709 Handle(TCollection_HAsciiString) ColName = new TCollection_HAsciiString ( "" );
710 Handle(StepVisual_ColourRgb) ColRGB = new StepVisual_ColourRgb;
711 NCollection_Vec3<Standard_Real> aColor_sRGB;
712 C.Values (aColor_sRGB.r(), aColor_sRGB.g(), aColor_sRGB.b(), Quantity_TOC_sRGB);
713 ColRGB->Init ( ColName, aColor_sRGB.r(), aColor_sRGB.g(), aColor_sRGB.b() );
719 //=======================================================================
720 //function : EncodeColor
722 //=======================================================================
724 Handle(StepVisual_Colour) STEPConstruct_Styles::EncodeColor
725 (const Quantity_Color &C,
726 STEPConstruct_DataMapOfAsciiStringTransient &DPDCs,
727 STEPConstruct_DataMapOfPointTransient &ColRGBs)
729 // detect if color corresponds to one of pre-defined colors
730 Standard_CString cName = 0;
731 if ( C == Quantity_Color(Quantity_NOC_GREEN) ) cName = "green";
732 else if ( C == Quantity_Color(Quantity_NOC_RED) ) cName = "red";
733 else if ( C == Quantity_Color(Quantity_NOC_BLUE1) ) cName = "blue";
734 else if ( C == Quantity_Color(Quantity_NOC_YELLOW) ) cName = "yellow";
735 else if ( C == Quantity_Color(Quantity_NOC_MAGENTA1) ) cName = "magenta";
736 else if ( C == Quantity_Color(Quantity_NOC_CYAN1) ) cName = "cyan";
737 else if ( C == Quantity_Color(Quantity_NOC_BLACK) ) cName = "black";
738 else if ( C == Quantity_Color(Quantity_NOC_WHITE) ) cName = "white";
741 Handle(StepVisual_DraughtingPreDefinedColour) ColPr;
742 TCollection_AsciiString aName(cName);
743 if(DPDCs.IsBound(aName)) {
744 ColPr = Handle(StepVisual_DraughtingPreDefinedColour)::DownCast(DPDCs.Find(aName));
745 if(!ColPr.IsNull()) return ColPr;
747 ColPr = new StepVisual_DraughtingPreDefinedColour;
748 Handle(StepVisual_PreDefinedItem) preDef = new StepVisual_PreDefinedItem;
749 preDef->Init(new TCollection_HAsciiString(cName));
750 ColPr->SetPreDefinedItem(preDef);
751 DPDCs.Bind(aName,ColPr);
755 Handle(StepVisual_ColourRgb) ColRGB;
757 C.Values (P.ChangeCoord().ChangeData()[0],
758 P.ChangeCoord().ChangeData()[1],
759 P.ChangeCoord().ChangeData()[2],
761 if(ColRGBs.IsBound(P)) {
762 ColRGB = Handle(StepVisual_ColourRgb)::DownCast(ColRGBs.Find(P));
763 if(!ColRGB.IsNull()) return ColRGB;
765 Handle(TCollection_HAsciiString) ColName = new TCollection_HAsciiString ( "" );
766 ColRGB = new StepVisual_ColourRgb;
767 ColRGB->Init ( ColName, P.Coord (1), P.Coord (2), P.Coord (3) );
768 ColRGBs.Bind(P,ColRGB);
774 //=======================================================================
775 //function : DecodeColor
777 //=======================================================================
779 Standard_Boolean STEPConstruct_Styles::DecodeColor (const Handle(StepVisual_Colour) &Colour, Quantity_Color &Col)
781 if ( Colour->IsKind (STANDARD_TYPE(StepVisual_ColourRgb)) ) {
782 Handle(StepVisual_ColourRgb) rgb = Handle(StepVisual_ColourRgb)::DownCast ( Colour );
783 if( rgb->Red()>1. || rgb->Green()>1. || rgb->Blue()>1. ) {
784 Standard_Real norm = rgb->Red();
785 if(norm<rgb->Green()) norm = rgb->Green();
786 if(norm<rgb->Blue()) norm = rgb->Blue();
787 Col.SetValues(rgb->Red()/norm, rgb->Green()/norm,
788 rgb->Blue()/norm, Quantity_TOC_sRGB);
791 Col.SetValues(rgb->Red(), rgb->Green(), rgb->Blue(), Quantity_TOC_sRGB);
792 return Standard_True;
794 else if ( Colour->IsKind (STANDARD_TYPE(StepVisual_PreDefinedColour)) ) {
795 Handle(StepVisual_PreDefinedColour) pdc =
796 Handle(StepVisual_PreDefinedColour)::DownCast ( Colour );
797 Handle(StepVisual_PreDefinedItem) pdi = pdc->GetPreDefinedItem();
798 const TCollection_AsciiString name = pdi->Name()->String();
799 if ( name.IsEqual ( "red" ) ) Col.SetValues ( Quantity_NOC_RED );
800 else if ( name.IsEqual ( "green" ) ) Col.SetValues ( Quantity_NOC_GREEN );
801 else if ( name.IsEqual ( "blue" ) ) Col.SetValues ( Quantity_NOC_BLUE1 );
802 else if ( name.IsEqual ( "yellow" ) ) Col.SetValues ( Quantity_NOC_YELLOW );
803 else if ( name.IsEqual ( "magenta" ) ) Col.SetValues ( Quantity_NOC_MAGENTA1 );
804 else if ( name.IsEqual ( "cyan" ) ) Col.SetValues ( Quantity_NOC_CYAN1 );
805 else if ( name.IsEqual ( "black" ) ) Col.SetValues ( Quantity_NOC_BLACK );
806 else if ( name.IsEqual ( "white" ) ) Col.SetValues ( Quantity_NOC_WHITE );
809 std::cout << "Error: color name \"" << name << "\" is not recognized" << std::endl;
811 return Standard_False;
813 return Standard_True;
815 return Standard_False;