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