b311480e |
1 | // Created by: CKY / Contract Toubro-Larsen |
2 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
7fd59977 |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
7fd59977 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
16 | //-------------------------------------------------------------------- |
7fd59977 |
17 | //-------------------------------------------------------------------- |
18 | |
42cf5bc1 |
19 | #include <gp_Pnt2d.hxx> |
20 | #include <gp_XY.hxx> |
21 | #include <gp_XYZ.hxx> |
22 | #include <IGESData_IGESEntity.hxx> |
23 | #include <IGESData_ViewKindEntity.hxx> |
24 | #include <IGESDraw_DrawingWithRotation.hxx> |
7fd59977 |
25 | #include <IGESDraw_PerspectiveView.hxx> |
42cf5bc1 |
26 | #include <IGESDraw_View.hxx> |
7fd59977 |
27 | #include <IGESGraph_DrawingSize.hxx> |
42cf5bc1 |
28 | #include <IGESGraph_DrawingUnits.hxx> |
7fd59977 |
29 | #include <Interface_Macros.hxx> |
42cf5bc1 |
30 | #include <Standard_DimensionMismatch.hxx> |
31 | #include <Standard_OutOfRange.hxx> |
32 | #include <Standard_Type.hxx> |
7fd59977 |
33 | |
92efcf78 |
34 | IMPLEMENT_STANDARD_RTTIEXT(IGESDraw_DrawingWithRotation,IGESData_IGESEntity) |
35 | |
b311480e |
36 | IGESDraw_DrawingWithRotation::IGESDraw_DrawingWithRotation () { } |
7fd59977 |
37 | |
38 | |
39 | void IGESDraw_DrawingWithRotation::Init |
40 | (const Handle(IGESDraw_HArray1OfViewKindEntity)& allViews, |
41 | const Handle(TColgp_HArray1OfXY)& allViewOrigins, |
42 | const Handle(TColStd_HArray1OfReal)& allOrientationAngles, |
43 | const Handle(IGESData_HArray1OfIGESEntity)& allAnnotations) |
44 | { |
45 | Standard_Integer Len = allViews->Length(); |
46 | if ( allViews->Lower() != 1 || |
47 | (allViewOrigins->Lower() != 1 || allViewOrigins->Length() != Len) || |
48 | (allOrientationAngles->Lower() != 1 || allOrientationAngles->Length() != Len) ) |
49 | Standard_DimensionMismatch::Raise |
50 | ("IGESDraw_DrawingWithRotation : Init"); |
51 | if (!allAnnotations.IsNull()) |
52 | if (allAnnotations->Lower() != 1) Standard_DimensionMismatch::Raise |
53 | ("IGESDraw_DrawingWithRotation : Init"); |
54 | |
55 | theViews = allViews; |
56 | theViewOrigins = allViewOrigins; |
57 | theOrientationAngles = allOrientationAngles; |
58 | theAnnotations = allAnnotations; |
59 | InitTypeAndForm(404,1); |
60 | } |
61 | |
62 | Standard_Integer IGESDraw_DrawingWithRotation::NbViews () const |
63 | { |
64 | return (theViews->Length()); |
65 | } |
66 | |
67 | Handle(IGESData_ViewKindEntity) IGESDraw_DrawingWithRotation::ViewItem |
68 | (const Standard_Integer Index) const |
69 | { |
70 | return (theViews->Value(Index)); |
71 | } |
72 | |
73 | gp_Pnt2d IGESDraw_DrawingWithRotation::ViewOrigin |
74 | (const Standard_Integer Index) const |
75 | { |
76 | return ( gp_Pnt2d (theViewOrigins->Value(Index)) ); |
77 | } |
78 | |
79 | Standard_Real IGESDraw_DrawingWithRotation::OrientationAngle |
80 | (const Standard_Integer Index) const |
81 | { |
82 | return ( theOrientationAngles->Value(Index) ); |
83 | } |
84 | |
85 | Standard_Integer IGESDraw_DrawingWithRotation::NbAnnotations () const |
86 | { |
87 | return (theAnnotations.IsNull() ? 0 : theAnnotations->Length() ); |
88 | } |
89 | |
90 | Handle(IGESData_IGESEntity) IGESDraw_DrawingWithRotation::Annotation |
91 | (const Standard_Integer Index) const |
92 | { |
93 | return ( theAnnotations->Value(Index) ); |
94 | } |
95 | |
96 | gp_XY IGESDraw_DrawingWithRotation::ViewToDrawing |
97 | (const Standard_Integer NumView, const gp_XYZ& ViewCoords) const |
98 | { |
99 | gp_XY thisOrigin = theViewOrigins->Value(NumView); |
100 | Standard_Real XOrigin = thisOrigin.X(); |
101 | Standard_Real YOrigin = thisOrigin.Y(); |
102 | Standard_Real theScaleFactor=0.; |
103 | |
104 | Handle(IGESData_ViewKindEntity) tempView = theViews->Value(NumView); |
105 | if (tempView->IsKind(STANDARD_TYPE(IGESDraw_View))) |
106 | { |
107 | DeclareAndCast(IGESDraw_View, thisView, tempView); |
108 | theScaleFactor = thisView->ScaleFactor(); |
109 | } |
110 | else if (tempView->IsKind(STANDARD_TYPE(IGESDraw_PerspectiveView))) |
111 | { |
112 | DeclareAndCast(IGESDraw_PerspectiveView, thisView, tempView); |
113 | theScaleFactor = thisView->ScaleFactor(); |
114 | } |
115 | |
116 | Standard_Real XV = ViewCoords.X(); |
117 | Standard_Real YV = ViewCoords.Y(); |
118 | |
119 | Standard_Real theta = theOrientationAngles->Value(NumView); |
120 | |
121 | Standard_Real XD = |
122 | XOrigin + theScaleFactor * ( XV * Cos(theta) - YV * Sin(theta) ); |
123 | Standard_Real YD = |
124 | YOrigin + theScaleFactor * ( XV * Sin(theta) + YV * Cos(theta) ); |
125 | |
126 | return ( gp_XY(XD, YD) ); |
127 | } |
128 | |
129 | |
130 | Standard_Boolean IGESDraw_DrawingWithRotation::DrawingUnit |
131 | (Standard_Real& val) const |
132 | { |
133 | val = 0.; |
134 | Handle(Standard_Type) typunit = STANDARD_TYPE(IGESGraph_DrawingUnits); |
135 | if (NbTypedProperties(typunit) != 1) return Standard_False; |
136 | DeclareAndCast(IGESGraph_DrawingUnits,units,TypedProperty(typunit)); |
137 | if (units.IsNull()) return Standard_False; |
138 | val = units->UnitValue(); |
139 | return Standard_True; |
140 | } |
141 | |
142 | Standard_Boolean IGESDraw_DrawingWithRotation::DrawingSize |
143 | (Standard_Real& X, Standard_Real& Y) const |
144 | { |
145 | X = Y = 0.; |
146 | Handle(Standard_Type) typsize = STANDARD_TYPE(IGESGraph_DrawingSize); |
147 | if (NbTypedProperties(typsize) != 1) return Standard_False; |
148 | DeclareAndCast(IGESGraph_DrawingSize,size,TypedProperty(typsize)); |
149 | if (size.IsNull()) return Standard_False; |
150 | X = size->XSize(); Y = size->YSize(); |
151 | return Standard_True; |
152 | } |