0023831: Ghosts appears in 2D viewer of HLR MFC sample
[occt.git] / samples / mfc / standard / Common / OCC_2dDoc.cpp
CommitLineData
7fd59977 1// OCC_2dDoc.cpp: implementation of the OCC_2dDoc class.
2//
3//////////////////////////////////////////////////////////////////////
4
5#include <stdafx.h>
6
7#include "OCC_2dDoc.h"
8
5c1f974e 9#include "OCC_App.h"
7fd59977 10#include "OCC_2dView.h"
11
12IMPLEMENT_DYNCREATE(OCC_2dDoc, CDocument)
13
14//////////////////////////////////////////////////////////////////////
15// Construction/Destruction
16//////////////////////////////////////////////////////////////////////
17
5c1f974e 18OCC_2dDoc::OCC_2dDoc() : OCC_BaseDoc()
7fd59977 19{
5c1f974e 20 // Get the Graphic Driver from the application
21 Handle(Graphic3d_GraphicDriver) aGraphicDriver =
22 ((OCC_App*)AfxGetApp())->GetGraphicDriver();
7fd59977 23
5c1f974e 24 // create the Viewer
25 TCollection_ExtendedString aName ("Viewer 2D");
26 TCollection_AsciiString aDomain ("My Domain");
27
28 myViewer = new V3d_Viewer (aGraphicDriver,
29 aName.ToExtString(),
30 aDomain.ToCString());
31
32 myViewer->SetDefaultLights();
33 myViewer->SetLightOn();
34 myViewer->SetDefaultViewProj (V3d_Zpos);
35
36 // set default values for grids
37 myViewer->SetCircularGridValues (0, 0, 10, 8, 0);
38 myViewer->SetRectangularGridValues (0, 0, 10, 10, 0);
7fd59977 39
5c1f974e 40 myAISContext = new AIS_InteractiveContext (myViewer);
41
42 AfxInitRichEdit();
7fd59977 43}
44
5c1f974e 45void OCC_2dDoc::FitAll2DViews(Standard_Boolean theUpdateViewer)
7fd59977 46{
5c1f974e 47 if (theUpdateViewer)
7fd59977 48 {
5c1f974e 49 myViewer->Update();
50 }
51
52 POSITION aPosition = GetFirstViewPosition();
53 while (aPosition != (POSITION)NULL)
54 {
55 OCC_2dView* aCurrentView = (OCC_2dView*)GetNextView (aPosition);
56 ASSERT_VALID (aCurrentView);
57 aCurrentView->GetV2dView()->FitAll();
7fd59977 58 }
59}
60
5c1f974e 61void OCC_2dDoc::MoveEvent(const Standard_Integer theMouseX,
62 const Standard_Integer theMouseY,
63 const Handle(V3d_View)& theView)
7fd59977 64{
5c1f974e 65 myAISContext->MoveTo (theMouseX, theMouseY, theView);
7fd59977 66}
67
5c1f974e 68void OCC_2dDoc::ShiftMoveEvent(const Standard_Integer theMouseX,
69 const Standard_Integer theMouseY,
70 const Handle(V3d_View)& theView)
7fd59977 71{
5c1f974e 72 myAISContext->MoveTo (theMouseX, theMouseY, theView);
7fd59977 73}