summaryrefslogtreecommitdiff
path: root/src/IGESDraw/IGESDraw_DrawingWithRotation.cxx
blob: 36290fa77767a30b3728a23f6d3572c5217efc4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//--------------------------------------------------------------------
//
//  File Name : IGESDraw_DrawingWithRotation.cxx
//  Date      :
//  Author    : CKY / Contract Toubro-Larsen
//  Copyright : MATRA-DATAVISION 1993
//
//--------------------------------------------------------------------

#include <IGESDraw_DrawingWithRotation.ixx>
#include <IGESDraw_View.hxx>
#include <IGESDraw_PerspectiveView.hxx>

#include <IGESGraph_DrawingUnits.hxx>
#include <IGESGraph_DrawingSize.hxx>

#include <Interface_Macros.hxx>


    IGESDraw_DrawingWithRotation::IGESDraw_DrawingWithRotation ()    {  }


    void IGESDraw_DrawingWithRotation::Init
  (const Handle(IGESDraw_HArray1OfViewKindEntity)& allViews,
   const Handle(TColgp_HArray1OfXY)&               allViewOrigins,
   const Handle(TColStd_HArray1OfReal)&            allOrientationAngles,
   const Handle(IGESData_HArray1OfIGESEntity)&     allAnnotations)
{
  Standard_Integer Len  = allViews->Length();
  if ( allViews->Lower() != 1 ||
      (allViewOrigins->Lower() != 1 || allViewOrigins->Length() != Len) ||
      (allOrientationAngles->Lower() != 1 || allOrientationAngles->Length() != Len) )
    Standard_DimensionMismatch::Raise
      ("IGESDraw_DrawingWithRotation : Init");
  if (!allAnnotations.IsNull())
    if (allAnnotations->Lower() != 1) Standard_DimensionMismatch::Raise
      ("IGESDraw_DrawingWithRotation : Init");

  theViews             = allViews; 
  theViewOrigins       = allViewOrigins; 
  theOrientationAngles = allOrientationAngles; 
  theAnnotations       = allAnnotations; 
  InitTypeAndForm(404,1);
}

    Standard_Integer IGESDraw_DrawingWithRotation::NbViews () const
{
  return (theViews->Length());
}

    Handle(IGESData_ViewKindEntity) IGESDraw_DrawingWithRotation::ViewItem
  (const Standard_Integer Index) const
{
  return (theViews->Value(Index));
}

    gp_Pnt2d IGESDraw_DrawingWithRotation::ViewOrigin
  (const Standard_Integer Index) const
{
  return ( gp_Pnt2d (theViewOrigins->Value(Index)) );
}

    Standard_Real IGESDraw_DrawingWithRotation::OrientationAngle
  (const Standard_Integer Index) const
{
  return ( theOrientationAngles->Value(Index) );
}

    Standard_Integer IGESDraw_DrawingWithRotation::NbAnnotations () const
{
  return (theAnnotations.IsNull() ? 0 : theAnnotations->Length() );
}

    Handle(IGESData_IGESEntity) IGESDraw_DrawingWithRotation::Annotation
  (const Standard_Integer Index) const
{
  return ( theAnnotations->Value(Index) );
}

    gp_XY IGESDraw_DrawingWithRotation::ViewToDrawing
  (const Standard_Integer NumView, const gp_XYZ& ViewCoords) const
{
  gp_XY         thisOrigin       = theViewOrigins->Value(NumView);
  Standard_Real XOrigin          = thisOrigin.X();
  Standard_Real YOrigin          = thisOrigin.Y();
  Standard_Real theScaleFactor=0.;

  Handle(IGESData_ViewKindEntity) tempView = theViews->Value(NumView);
  if (tempView->IsKind(STANDARD_TYPE(IGESDraw_View)))
    {
      DeclareAndCast(IGESDraw_View, thisView, tempView);
      theScaleFactor   = thisView->ScaleFactor();
    }
  else if (tempView->IsKind(STANDARD_TYPE(IGESDraw_PerspectiveView)))
    {
      DeclareAndCast(IGESDraw_PerspectiveView, thisView, tempView);
      theScaleFactor   = thisView->ScaleFactor();
    }

  Standard_Real XV               = ViewCoords.X();
  Standard_Real YV               = ViewCoords.Y();

  Standard_Real theta            = theOrientationAngles->Value(NumView);

  Standard_Real XD = 
    XOrigin + theScaleFactor * ( XV * Cos(theta) - YV * Sin(theta) );
  Standard_Real YD = 
    YOrigin + theScaleFactor * ( XV * Sin(theta) + YV * Cos(theta) );

  return ( gp_XY(XD, YD) );
}


    Standard_Boolean  IGESDraw_DrawingWithRotation::DrawingUnit
  (Standard_Real& val) const
{
  val = 0.;
  Handle(Standard_Type) typunit = STANDARD_TYPE(IGESGraph_DrawingUnits);
  if (NbTypedProperties(typunit) != 1) return Standard_False;
  DeclareAndCast(IGESGraph_DrawingUnits,units,TypedProperty(typunit)); 
  if (units.IsNull()) return Standard_False;
  val = units->UnitValue();
  return Standard_True;
}

    Standard_Boolean  IGESDraw_DrawingWithRotation::DrawingSize
  (Standard_Real& X, Standard_Real& Y) const
{
  X = Y = 0.;
  Handle(Standard_Type) typsize = STANDARD_TYPE(IGESGraph_DrawingSize);
  if (NbTypedProperties(typsize) != 1) return Standard_False;
  DeclareAndCast(IGESGraph_DrawingSize,size,TypedProperty(typsize)); 
  if (size.IsNull()) return Standard_False;
  X = size->XSize();  Y = size->YSize();
  return Standard_True;
}