7fd59977 |
1 | #include "stdafx.h" |
2 | |
3 | #include "Sample2D_Image.h" |
7fd59977 |
4 | |
5c1f974e |
5 | IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_TexturedShape) |
7fd59977 |
6 | |
5c1f974e |
7 | Sample2D_Image::Sample2D_Image(TCollection_AsciiString& aFileName, |
8 | const Quantity_Length X, |
9 | const Quantity_Length Y, |
10 | const Quantity_Factor aScale) |
11 | :AIS_TexturedShape(TopoDS_Shape()) |
7fd59977 |
12 | { |
5c1f974e |
13 | myFilename = aFileName; |
14 | myX = X; |
15 | myY = Y; |
16 | myScale = aScale; |
7fd59977 |
17 | } |
5c1f974e |
18 | void Sample2D_Image::MakeShape() |
7fd59977 |
19 | { |
5c1f974e |
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); |
7fd59977 |
30 | } |
31 | |
5c1f974e |
32 | void Sample2D_Image::SetContext(const Handle(AIS_InteractiveContext)& theContext) |
7fd59977 |
33 | { |
7fd59977 |
34 | if(theContext.IsNull() || theContext->CurrentViewer().IsNull()) return; |
5c1f974e |
35 | AIS_InteractiveObject::SetContext(theContext); |
36 | MakeShape(); |
37 | this->Set(TopoDS_Shape(myFace)); |
38 | this->SetTextureFileName(myFilename); |
7fd59977 |
39 | |
7fd59977 |
40 | } |
41 | |
7fd59977 |
42 | |
43 | |