1 // Created on: 1999-09-10
2 // Created by: Andrey BETENEV
3 // Copyright (c) 1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 #ifndef _STEPConstruct_Styles_HeaderFile
18 #define _STEPConstruct_Styles_HeaderFile
19 
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23 
24 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
25 #include <TColStd_IndexedMapOfTransient.hxx>
26 #include <TColStd_SequenceOfTransient.hxx>
27 #include <STEPConstruct_Tool.hxx>
28 #include <Standard_Boolean.hxx>
29 #include <Standard_Integer.hxx>
30 #include <TColStd_HSequenceOfTransient.hxx>
31 #include <STEPConstruct_DataMapOfAsciiStringTransient.hxx>
32 #include <STEPConstruct_DataMapOfPointTransient.hxx>
33 class XSControl_WorkSession;
34 class StepVisual_StyledItem;
35 class StepRepr_RepresentationItem;
36 class StepVisual_PresentationStyleAssignment;
37 class TopoDS_Shape;
38 class StepRepr_RepresentationContext;
39 class StepVisual_MechanicalDesignGeometricPresentationRepresentation;
40 class StepShape_ContextDependentShapeRepresentation;
41 class StepRepr_ProductDefinitionShape;
42 class StepVisual_Colour;
43 class Quantity_Color;
44 
45 
46 //! Provides a mechanism for reading and writing shape styles
47 //! (such as color) to and from the STEP file
48 //! This tool maintains a list of styles, either taking them
49 //! from STEP model (reading), or filling it by calls to
50 //! AddStyle or directly (writing).
51 //! Some methods deal with general structures of styles and
52 //! presentations in STEP, but there are methods which deal
53 //! with particular implementation of colors (as described in RP)
54 class STEPConstruct_Styles  : public STEPConstruct_Tool
55 {
56 public:
57 
58   DEFINE_STANDARD_ALLOC
59 
60 
61   //! Creates an empty tool
62   Standard_EXPORT STEPConstruct_Styles();
63 
64   //! Creates a tool and initializes it
65   Standard_EXPORT STEPConstruct_Styles(const Handle(XSControl_WorkSession)& WS);
66 
67   //! Initializes tool; returns True if succeeded
68   Standard_EXPORT Standard_Boolean Init (const Handle(XSControl_WorkSession)& WS);
69 
70   //! Returns number of defined styles
71   Standard_EXPORT Standard_Integer NbStyles() const;
72 
73   //! Returns style with given index
74   Standard_EXPORT Handle(StepVisual_StyledItem) Style (const Standard_Integer i) const;
75 
76   //! Clears all defined styles and PSA sequence
77   Standard_EXPORT void ClearStyles();
78 
79   //! Adds a style to a sequence
80   Standard_EXPORT void AddStyle (const Handle(StepVisual_StyledItem)& style);
81 
82   //! Create a style linking giving PSA to the item, and add it to the
83   //! sequence of stored styles. If Override is not Null, then
84   //! the resulting style will be of the subtype OverridingStyledItem.
85   Standard_EXPORT Handle(StepVisual_StyledItem) AddStyle (const Handle(StepRepr_RepresentationItem)& item, const Handle(StepVisual_PresentationStyleAssignment)& PSA, const Handle(StepVisual_StyledItem)& Override);
86 
87   //! Create a style linking giving PSA to the Shape, and add it to the
88   //! sequence of stored styles. If Override is not Null, then
89   //! the resulting style will be of the subtype OverridingStyledItem.
90   //! The Sape is used to find corresponding STEP entity by call to
91   //! STEPConstruct::FindEntity(), then previous method is called.
92   Standard_EXPORT Handle(StepVisual_StyledItem) AddStyle (const TopoDS_Shape& Shape, const Handle(StepVisual_PresentationStyleAssignment)& PSA, const Handle(StepVisual_StyledItem)& Override);
93 
94   //! Create MDGPR, fill it with all the styles previously defined,
95   //! and add it to the model
96   Standard_EXPORT Standard_Boolean CreateMDGPR (const Handle(StepRepr_RepresentationContext)& Context, Handle(StepVisual_MechanicalDesignGeometricPresentationRepresentation)& MDGPR);
97 
98   //! Create MDGPR, fill it with all the styles previously defined,
99   //! and add it to the model
100   //! IMPORTANT: <initPDS> must be null when use for NAUO colors
101   //! <initPDS> initialised only for SHUO case.
102   Standard_EXPORT Standard_Boolean CreateNAUOSRD (const Handle(StepRepr_RepresentationContext)& Context, const Handle(StepShape_ContextDependentShapeRepresentation)& CDSR, const Handle(StepRepr_ProductDefinitionShape)& initPDS);
103 
104   //! Searches the STEP model for the RepresentationContext in which
105   //! given shape is defined. This context (if found) can be used
106   //! then in call to CreateMDGPR()
107   Standard_EXPORT Handle(StepRepr_RepresentationContext) FindContext (const TopoDS_Shape& Shape) const;
108 
109   //! Searches the STEP model for the MDGPR or DM entities
110   //! (which bring styles) and fills sequence of styles
111   Standard_EXPORT Standard_Boolean LoadStyles();
112 
113   //! Searches the STEP model for the INISIBILITY enteties
114   //! (which bring styles) and fills out sequence of styles
115   Standard_EXPORT Standard_Boolean LoadInvisStyles (Handle(TColStd_HSequenceOfTransient)& InvSyles) const;
116 
117   //! Create a PresentationStyleAssignment entity which defines
118   //! two colors (for filling surfaces and curves)
119   //! if isForNAUO true then returns PresentationStyleByContext
120   Standard_EXPORT Handle(StepVisual_PresentationStyleAssignment) MakeColorPSA (const Handle(StepRepr_RepresentationItem)& item, const Handle(StepVisual_Colour)& SurfCol, const Handle(StepVisual_Colour)& CurveCol, const Standard_Boolean isForNAUO = Standard_False) const;
121 
122   //! Returns a PresentationStyleAssignment entity which defines
123   //! surface and curve colors as Col. This PSA is either created
124   //! or taken from internal map where all PSAs created by this
125   //! method are remembered.
126   Standard_EXPORT Handle(StepVisual_PresentationStyleAssignment) GetColorPSA (const Handle(StepRepr_RepresentationItem)& item, const Handle(StepVisual_Colour)& Col);
127 
128   //! Extract color definitions from the style entity
129   //! For each type of color supported, result can be either
130   //! NULL if it is not defined by that style, or last
131   //! definition (if they are 1 or more)
132   Standard_EXPORT Standard_Boolean GetColors (const Handle(StepVisual_StyledItem)& style, Handle(StepVisual_Colour)& SurfCol, Handle(StepVisual_Colour)& BoundCol, Handle(StepVisual_Colour)& CurveCol, Standard_Boolean& IsComponent) const;
133 
134   //! Create STEP color entity by given Quantity_Color
135   //! The analysis is performed for whether the color corresponds to
136   //! one of standard colors predefined in STEP. In that case,
137   //! PredefinedColour entity is created instead of RGBColour
138   Standard_EXPORT static Handle(StepVisual_Colour) EncodeColor (const Quantity_Color& Col);
139 
140   //! Create STEP color entity by given Quantity_Color
141   //! The analysis is performed for whether the color corresponds to
142   //! one of standard colors predefined in STEP. In that case,
143   //! PredefinedColour entity is created instead of RGBColour
144   Standard_EXPORT static Handle(StepVisual_Colour) EncodeColor (const Quantity_Color& Col, STEPConstruct_DataMapOfAsciiStringTransient& DPDCs, STEPConstruct_DataMapOfPointTransient& ColRGBs);
145 
146   //! Decodes STEP color and fills the Quantity_Color.
147   //! Returns True if OK or False if color is not recognized
148   Standard_EXPORT static Standard_Boolean DecodeColor (const Handle(StepVisual_Colour)& Colour, Quantity_Color& Col);
149 
150 
151 
152 
153 protected:
154 
155 
156 
157 
158 
159 private:
160 
161 
162 
163   TColStd_IndexedDataMapOfTransientTransient myMapOfStyles;
164   TColStd_IndexedMapOfTransient myStyles;
165   TColStd_SequenceOfTransient myPSA;
166 
167 
168 };
169 
170 
171 
172 
173 
174 
175 
176 #endif // _STEPConstruct_Styles_HeaderFile
177