0028316: Coding Rules - Elimilate confusing aliases of Standard_Real type in V3d_View
[occt.git] / samples / mfc / standard / Common / Primitive / Sample2D_Image.cpp
1 #include "stdafx.h"
2
3 #include "Sample2D_Image.h"
4
5 IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_TexturedShape)
6
7 Sample2D_Image::Sample2D_Image(TCollection_AsciiString& aFileName,
8                                const Standard_Real X,
9                                const Standard_Real Y,
10                                const Standard_Real aScale)
11     :AIS_TexturedShape(TopoDS_Shape())
12 {
13   myFilename = aFileName;
14   myX = X;
15   myY = Y;  
16   myScale = aScale;
17 }
18 void Sample2D_Image::MakeShape()
19 {
20   Handle(Graphic3d_Texture1D) anImageTexture = 
21     new Graphic3d_Texture1Dsegment(myFilename);
22   Standard_Real coeff = (Standard_Real)(anImageTexture->GetImage()->Height())/
23     (anImageTexture->GetImage()->Width())*myScale;
24   TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(myX,myY,0.), gp_Pnt(100*myScale+myX,myY,0.));
25   TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(100*myScale+myX,myY,0.), gp_Pnt(100*myScale+myX,100*coeff+myY,0.));
26   TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(100*myScale+myX,100*coeff+myY,0.), gp_Pnt(myX,100*coeff+myY,0.));
27   TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(myX,100*coeff+myY,0.), gp_Pnt(myX,myY,0.));
28   TopoDS_Wire anImageBounds = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);
29   myFace = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),anImageBounds);
30 }
31
32 void Sample2D_Image::SetContext(const Handle(AIS_InteractiveContext)& theContext) 
33 {
34   if(theContext.IsNull() || theContext->CurrentViewer().IsNull()) return;
35   AIS_InteractiveObject::SetContext(theContext);
36   MakeShape();
37   this->Set(TopoDS_Shape(myFace));
38   this->SetTextureFileName(myFilename);
39
40 }
41
42
43