0022962: Invalid realization of reading and writing material in STEP.
[occt.git] / src / QADBMReflex / QADBMReflex_OCC749PrsUseVertexC.cxx
1 // File:        QADBMReflex_OCC749PrsUseVertexC.cxx
2 // Created:     Mon Oct  7 15:01:41 2002
3 // Author:      QA Admin
4 //              <qa@russox>
5
6
7 #include <QADBMReflex_OCC749PrsUseVertexC.ixx>
8
9 #include <Prs3d_Root.hxx>
10 #include <Graphic3d_Group.hxx>
11 #include <Graphic3d_Vertex.hxx>
12 #include <Aspect_Array1OfEdge.hxx>
13 #include <Graphic3d_AspectFillArea3d.hxx>
14 #include <Graphic3d_MaterialAspect.hxx>
15 #include <Quantity_Color.hxx>
16 #include <Graphic3d_Array1OfVertexC.hxx>
17 #include <Aspect_Edge.hxx>
18
19
20 #include <Graphic3d_Array1OfVertex.hxx>
21 #include <OSD_Timer.hxx>
22
23
24 //=======================================================================
25 //function : QADBMReflex_OCC749PrsUseVertex
26 //purpose  : 
27 //=======================================================================
28
29   QADBMReflex_OCC749PrsUseVertexC::QADBMReflex_OCC749PrsUseVertexC( const Standard_Boolean Reflection,const Quantity_Color& InteriorColor,const Quantity_Color& EdgeColor,const Quantity_Color& EdgeColor2,const Standard_Integer XCount,const Standard_Integer YCount,const Standard_Integer BoxSize,const Graphic3d_MaterialAspect& MaterialAspect,const Standard_Boolean Material,const Standard_Boolean Timer ):QADBMReflex_OCC749Prs(Reflection,InteriorColor,EdgeColor,EdgeColor2,XCount,YCount,BoxSize,MaterialAspect,Material,Timer) {
30 }
31
32 static OSD_Timer Timer;
33
34 //=======================================================================
35 //function : Compute
36 //purpose  : 
37 //=======================================================================
38
39 void QADBMReflex_OCC749PrsUseVertexC::Compute(const Handle(PrsMgr_PresentationManager3d)& aPrsMgr,
40                                               const Handle(Prs3d_Presentation)& aPresentation,
41                                               const Standard_Integer aMode )
42 {
43   Standard_Boolean BooleanTimer = GetTimer();
44   if (BooleanTimer) {
45     Timer.Reset ();
46     Timer.Start ();
47   }
48
49   aPresentation->Clear();
50   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(aPresentation);
51
52   Graphic3d_MaterialAspect aFlatMat; 
53   Standard_Boolean BooleanMaterial = GetMaterial();
54   if (BooleanMaterial) {
55     aFlatMat = GetMaterialAspect(); 
56   }
57
58   Standard_Boolean BooleanReflection = GetReflection();
59   if (BooleanReflection) {
60     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_AMBIENT);
61     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_DIFFUSE);
62     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_SPECULAR);
63     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_EMISSION);
64   } else {
65     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
66     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
67     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
68     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_EMISSION);
69   }
70
71   Quantity_Color InteriorColor = GetInteriorColor();
72   Quantity_Color EdgeColor     = GetEdgeColor();
73   Quantity_Color EdgeColor2    = GetEdgeColor2();
74
75   Standard_Integer XCOUNT = GetXCount();
76   Standard_Integer YCOUNT = GetYCount();
77   Standard_Integer BOXSIZE = GetBoxSize();
78
79   Handle(Graphic3d_AspectFillArea3d) Fill3d;
80   Fill3d = new Graphic3d_AspectFillArea3d(Aspect_IS_SOLID,
81                                           InteriorColor,
82                                           EdgeColor,
83                                           Aspect_TOL_SOLID,
84                                           1.5,
85                                           aFlatMat,
86                                           aFlatMat);
87   //Handle(Graphic3d_AspectFillArea3d) Fill3d = new Graphic3d_AspectFillArea3d();
88   //Fill3d->SetInteriorStyle(Aspect_IS_SOLID);
89
90   aGroup->SetGroupPrimitivesAspect(Fill3d);
91   aGroup->SetPrimitivesAspect(Fill3d);
92
93   aGroup->BeginPrimitives();
94
95   Standard_Integer i,j,z1=0,z2,zmax=XCOUNT;
96   if (YCOUNT > XCOUNT) zmax = YCOUNT;
97   for (i=0; i < XCOUNT; i++){
98     for (j=0; j < YCOUNT; j++){
99       //Quantity_NameOfColor aColor = Quantity_Color::Name(1., 
100       //                                                   (double)j/YCOUNT, 
101       //                                                   (double)i/XCOUNT);
102
103       Graphic3d_Array1OfVertexC aVertexes(1, 8); 
104       
105       z2 = BOXSIZE +(i*zmax - j*((Standard_Integer) zmax/2));
106       aVertexes(1).SetCoord(i*BOXSIZE, j*BOXSIZE, z1);
107       aVertexes(2).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE, z1);
108       aVertexes(3).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE + BOXSIZE, z1);
109       aVertexes(4).SetCoord(i*BOXSIZE, j*BOXSIZE + BOXSIZE, z1);
110       aVertexes(5).SetCoord(i*BOXSIZE, j*BOXSIZE, z2);
111       aVertexes(6).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE, z2);
112       aVertexes(7).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE + BOXSIZE, z2);
113       aVertexes(8).SetCoord(i*BOXSIZE, j*BOXSIZE + BOXSIZE, z2);
114       
115       /*
116       aVertexes(1).SetColor(EdgeColor);
117       aVertexes(2).SetColor(EdgeColor);
118       aVertexes(3).SetColor(EdgeColor2);
119       aVertexes(4).SetColor(EdgeColor2);
120       aVertexes(5).SetColor(EdgeColor2);
121       aVertexes(6).SetColor(EdgeColor2);
122       aVertexes(7).SetColor(EdgeColor);
123       aVertexes(8).SetColor(EdgeColor);
124       */ 
125       if ( (i!=0 || j!=0) ) {
126         aVertexes(1).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
127         aVertexes(2).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
128         aVertexes(3).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
129         aVertexes(4).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
130
131         aVertexes(5).SetColor(Quantity_Color(0., 1.-(double)j/YCOUNT, 1.-(double)i/XCOUNT, Quantity_TOC_RGB));
132         aVertexes(6).SetColor(Quantity_Color(0., 1.-(double)j/YCOUNT, 1.-(double)i/XCOUNT, Quantity_TOC_RGB));
133         aVertexes(7).SetColor(Quantity_Color(0., 1.-(double)j/YCOUNT, 1.-(double)i/XCOUNT, Quantity_TOC_RGB));
134         aVertexes(8).SetColor(Quantity_Color(0., 1.-(double)j/YCOUNT, 1.-(double)i/XCOUNT, Quantity_TOC_RGB));
135
136 /*      aVertexes(5).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
137         aVertexes(6).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
138         aVertexes(7).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
139         aVertexes(8).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
140 */
141       }
142
143       Aspect_Array1OfEdge aEdges(1, 24);
144       aEdges(1) = Aspect_Edge(1, 2, Aspect_TOE_VISIBLE);
145       aEdges(2) = Aspect_Edge(2, 3, Aspect_TOE_VISIBLE);
146       aEdges(3) = Aspect_Edge(3, 4, Aspect_TOE_VISIBLE);
147       aEdges(4) = Aspect_Edge(4, 1, Aspect_TOE_VISIBLE);
148
149       aEdges(5) = Aspect_Edge(5, 6, Aspect_TOE_VISIBLE);
150       aEdges(6) = Aspect_Edge(6, 7, Aspect_TOE_VISIBLE);
151       aEdges(7) = Aspect_Edge(7, 8, Aspect_TOE_VISIBLE);
152       aEdges(8) = Aspect_Edge(8, 5, Aspect_TOE_VISIBLE);
153
154       aEdges(9) = Aspect_Edge(1, 5, Aspect_TOE_VISIBLE);
155       aEdges(10) = Aspect_Edge(5, 6, Aspect_TOE_VISIBLE);
156       aEdges(11) = Aspect_Edge(6, 2, Aspect_TOE_VISIBLE);
157       aEdges(12) = Aspect_Edge(2, 1, Aspect_TOE_VISIBLE);
158
159       aEdges(13) = Aspect_Edge(6, 7, Aspect_TOE_VISIBLE);
160       aEdges(14) = Aspect_Edge(7, 3, Aspect_TOE_VISIBLE);
161       aEdges(15) = Aspect_Edge(3, 2, Aspect_TOE_VISIBLE);
162       aEdges(16) = Aspect_Edge(2, 6, Aspect_TOE_VISIBLE);
163
164       aEdges(17) = Aspect_Edge(3, 7, Aspect_TOE_VISIBLE);
165       aEdges(18) = Aspect_Edge(7, 8, Aspect_TOE_VISIBLE);
166       aEdges(19) = Aspect_Edge(8, 4, Aspect_TOE_VISIBLE);
167       aEdges(20) = Aspect_Edge(4, 3, Aspect_TOE_VISIBLE);
168
169       aEdges(21) = Aspect_Edge(4, 8, Aspect_TOE_VISIBLE);
170       aEdges(22) = Aspect_Edge(8, 5, Aspect_TOE_VISIBLE);
171       aEdges(23) = Aspect_Edge(5, 1, Aspect_TOE_VISIBLE);
172       aEdges(24) = Aspect_Edge(1, 4, Aspect_TOE_VISIBLE);
173
174       aGroup->QuadrangleSet(aVertexes, aEdges);
175     }
176   }
177   aGroup->EndPrimitives();
178
179   if (BooleanTimer) {
180     Timer.Stop ();
181     Timer.Show (cout);
182   }
183
184 }