Implement the 3D View Window in a Dialog with OpenCascade

xiaoxiao2021-03-06  35

Implement the 3D View Window in a Dialog with OpenCascade

[Preview]

http://www.box.net/shared/m8doih340s

[Source Code]

[MotiVation]

In my application about simulation on the Real Structure Elements in a construction, the calculation of some parameters is the mainly task which will be solved by the 3D graphic boolean method with Opencascade SDK. However, the white-box test unit should be established before the Main Module.

First, I Think That The Visual Tools Like The a Dialog OR a Window Will Be Helpful To Check The Boolean Arithmetic in My Application. Second, A WINDOW OCX OR LIGHT-Weight Visual Tool Is Mascara for The Future.

[Design Item]

A window class "C3DWnd" is designed for displaying the Simulated Elements using in the main module. And a instance of the C3DWnd is aggregated in a Dialog class. Based the Idea of ​​the Component, C3DWnd is nested in a DLL module which can be encapsulated AS An Ocx. on The Other Hand The "Dialog Class" is Nested in anony module as an "exe file".

[Code Background]

SYSTEM: Window XP, SP1;

Compiler: Visual C 6.0, SP6;

SDK: OpenCASCADE 5.1;

[Detail]

1, c3dwnd class

// 3dwnd.h: Header File

//

#include

#include

#include

#include

#include

#include

#ifndef __afxwin_h__

#error include 'stdafx.h' Before Including this file for pch

#ENDIF

#undef dllimpexp

#ifdef _3dviewDLL_

#define dllimpexp __declspec (dllexport)

#ELSE

#define dllimpexp

#ENDIF

/

// c3dwnd window

ENUM View3D_CurrentAction {

Curaction3d_nothing,

Curaction3D_Dynamiczooming,

Curaction3d_windowzooming, curaction3d_dynamicpanning,

Curaction3d_globalpanning,

Curaction3D_DynamicRotation,

Curaction3d_beginspotlight,

Curaction3d_targetspotlight,

Curaction3D_ENDSPOTLIGHT,

Curaction3d_beginpositionallight,

Curaction3D_BegindirectionAllight,

Curaction3D_ENDDIRECTIONALLIGHT

}

Class __declspec (dllexport) c3dwnd: Public CWnd

{

// construction

PUBLIC:

C3dWnd ();

// attributes

PUBLIC:

ENUM LINESTYLE {Solid, Dot, Shortdash, Longdash, Default};

// Operations

PUBLIC:

Virtual Void DrawRectangle (const standard_integer minx,

Const Standard_integer miny,

Const Standard_integer maxx,

Const Standard_integer MAXY,

Const Standard_Boolean Draw,

Const LinesTyle AlineStyle = Default);

// Overrides

// ClassWizard Generated Virtual Function Overrides

// {{AFX_VIRTUAL (C3DWnd)

PUBLIC:

//}} AFX_VIRTUAL

// Implementation

PUBLIC:

Void ShowFace (unsigned long nfaceid);

Void showSolid; Const Int Nid;

Void DispplayText ();

Void displayaxis ();

Void refresh ();

Void clear ();

Void Right ();

Void top ();

Void Left ();

Void Front ();

Void bottom ();

Void back ();

Void Axo ();

Void hideoff ();

Void hideon ();

void rotate ();

Void Panglobal ();

Void Pan ();

Void zoomprog ();

Void zoomwin ();

Void zooLall ();

Void showvolume ();

Virtual ~ c3dwnd ();

// generated message map functions

protected:

// {{AFX_MSG (C3DWND)

AFX_MSG Int Oncreate (LPCReatestruct LPCreateStruct);

AFX_MSG Void OnSize (Uint NTYPE, INT CX, INT CY);

AFX_MSG void onpaint ();

AFX_MSG Void OnMouseMove (uint nflags, cpoint point);

AFX_MSG Bool OnMousewheel (Uint Nflags, Short Zdelta, Cpoint Pt);

AFX_MSG Void ONLBUTTONUP (uint nflags, cpoint point);

AFX_MSG Void ONLBUTTONDOWN (Uint Nflags, Cpoint Point);

//}} AFX_MSG

Declare_message_map ()

Private:

// Pen for the frame:

CPEN * M_PPEN;

// 3D view pointer:

Handle_v3d_view m_pview;

// View container class:

Handle_v3d_viewer m_pviewer;

// WINDOW window frame:

Handle_wnt_window m_pwntwindow;

// Select graphics and manage graphics behavior:

Handle_ais_interactiveContext M_PaisconText;

// Initialize Windows NT Graphic Device:

Handle_graphic3d_wntgraphicDevice m_pgraphicDevice;

// position light setting

Handle_v3d_positionallight m_pcurrent_positionall;

// Hidden logo:

Standard_boolean m_degenerateemodeison;

// Current command status:

View3d_currentaction m_currentmode;

// Current zoom ratio:

Quantity_factor m_curzoom;

// The width of the image view:

Standard_Real M_RWIDTH;

// The height of the image view:

Standard_real m_rheight;

STANDARD_INTEGER M_ATX, M_ATY, M_ATZ; //

STANDARD_INTEGER M_EYEX, M_EYEY, M_EYEZ; //

}

/

// 3dwnd.cpp: importation file

//

#include "stdafx.h"

#include "3dwnd.h"

#include

#include

#include

#include

#include

#include "../../../../gcl7/source/geocalc/exportfunc.h"

#ifdef _Debug

// # Define new debug_new

#undef this_file

Static char this_file [] = __file__;

#ENDIF

GP_PNT P1, P2, P3;

/

// c3dwnd

STANDARD_INTEGER CXMIN = 0;

Standard_INTEGER CYMIN = 0;

STANDARD_INTEGER CXMAX = 600;

STANDARD_INTEGER CYMAX = 600;

Standard_integer Czmin = 0;

Standard_integer CZMAX = 200;

Standard_integer czoomstep = 20;

#define valzwmin 1

GP_PNT ConvertClicktopoint (Standard_Real X, Standard_real Y, Handle (V3D_View) Aview)

{

V3D_Coordinate Xeye, Yeye, Zeye, XAT, YAT, ZAT;

Aview-> Eye (Xeye, Yeye, ZEYE);

Aview-> At (XAT, YAT, ZAT);

GP_PNT Eyepoint (Xeye, Yeye, Zeye); GP_PNT ATPOINT (XAT, YAT, ZAT);

GP_VEC Eyevector (Eyepoint, Atpoint);

GP_DIR Eyedir (EyeVector);

GP_PLN PlaneOfTheView = GP_PLN (Atpoint, Eyedir);

Standard_real X, Y, Z;

Aview-> Convert (int (x), int (y), x, y, z);

GP_PNT CONVERTEDPOINT (X, Y, Z);

GP_PNT2D ConvertedPointonPlane = Projlib :: Project (PlaneOfTheView, Converted);

GP_PNT Resultpoint = Elslib :: Value (ConvertedPointonPlane.x (),

ConvertedPointonPlane.y (),

PlaneoftheView;

Return Resultpoint;

}

C3dWnd :: C3dWnd ()

{

m_pview = null;

M_PVIEWER = NULL;

m_paiscontext = null;

m_pgraphicDevice = null;

m_pwntwindow = NULL;

m_currentmode = curaction3d_nothing;

m_curzoom = 0;

m_ppen = NULL;

m_degeneratemodeison = standard_true;

}

C3dWnd :: ~ c3dWnd ()

{

m_pview-> remove ();

IF (m_ppen! = null)

delete m_ppen;

}

Begin_Message_Map (C3DWnd, CWND)

// {{AFX_MSG_MAP (C3DWND)

ON_WM_CREATE ()

ON_WM_SIZE ()

ON_WM_PAINT ()

ON_WM_MOUSEMOVE ()

ON_WM_MOUSEWHEEL ()

ON_WM_LBUTTONUP ()

ON_WM_LBUTTONDOWN ()

//}} AFX_MSG_MAP

END_MESSAGE_MAP ()

/

// C3dWnd Message Handlers

Int c3dwnd :: oncreate (lpcreatestruct lpcreatestruct)

{

IF (cwnd :: oncreate (lpcreatestruct) == -1)

Return -1;

// Todo: Add Your Specialized Creation Code Here

// CREATING VIEW

Try

{

m_pgraphicDevice = new graphic3d_wntgraphicDevice ();

}

Catch (Standard_Failure)

{

AfxMessageBox ("Fatal Error During Graphic Initialision);

}

M_PVIEWER = New V3D_Viewer (M_PgraphicDevice, (Short *) (""));

M_PViewer-> setdefaultlights ();

m_pviewer-> setLighton ();

// Create an interactive context based on the m_pviewer

m_paiscontext = new ais_interactivecontext (m_pviewer);

M_PView = m_pviewer-> creteView (); m_pview-> setdegeneratemodeon ();

// store for restore StateAfter rotation (Witch is in degenerated mode)

m_degeneratemodeison = standard_true;

// Creating new window and attaching it to view

M_PwntWindow = New Wnt_Window (M_PgraphicDevice, GetsafehWnd ());

m_pview-> setWindow;

IF (! m_pwntwindow-> ismapped ()) m_pwntwindow -> map ();

Displayaxis ();

Return 0;

}

Void C3dWnd :: OnSize (uint ntype, int Cx, int CY)

{

CWnd :: OnSize (NTYPE, CX, CY);

// Todo: Add your message Handler Code Here

IF (M_PView! = NULL) {

m_pview-> mustberesized ();

m_pview-> size (m_rwidth, m_rheight);

}

}

Void c3dwnd :: onpaint ()

{

CPAINTDC DC (this); // Device Context for Painting

CRECT ARECT;

GetWindowRect (all);

IF (m_rwidth! = all (fw () || m_rheight! = all.height ()) {

m_rwidth = all.width ();

m_rheight = all.height ();

:: PostMessage (GetSafehWnd (), WM_SIZE, SW_SHOW, M_RWIDTH M_RHEIGHT * 65536)

}

// Todo: Add your message Handler Code Here

m_pview-> redraw ();

// do not call cWnd :: onpaint () for Painting Messages

}

Void C3dWnd :: ShowVolume ()

{

Clear ();

Carrlong arrid;

GetSolidSID (Arrid);

For (int i = 0; I

Topods_Solid Solid = GetSolidByid (Arrid.getat (i));

Handle (AIS_SHAPE) AIS = New AIS_SHAPE (SOLID);

m_paiscontext-> setColor (AIS, Quantity_noc_green, Standard_false);

m_paiscontext-> setmaterial (AIS, Graphic3D_Nom_GOLD, STANDARD_FALSE);

m_paiscontext-> setDisplayMode (AIS, 1);

m_paiscontext-> Display (AIS, STANDARD_FALSE);

}

GetFacesID (Arrid);

For (i = 0; i

Topods_face face;

IF (! getfacebyid (arrid.getat (i), face) Break; handle (ais_shape) AIS = new AIS_SHAPE (FACE);

m_paiscontext-> setColor (AIS, Quantity_noc_gray99, Standard_false);

m_paiscontext-> setmaterial (AIS, Graphic3D_Nom_stone, Standard_false);

m_paiscontext-> setDisplayMode (AIS, 1);

m_paiscontext-> Display (AIS, STANDARD_FALSE);

}

m_pview-> fdoml ();

M_PView-> ZfitAll ();

/ * Topods_shape s = Brepprimapi_makewedge (600., 100., 80., 20.);

Handle (AIS_SHAPE) AIS1 = New AIS_SHAPE (S);

m_paiscontext-> setColor (AIS1, Quantity_noc_green, standard_false);

m_paiscontext-> setmaterial (AIS1, Graphic3D_Nom_Plastic, Standard_false);

m_paiscontext-> Display (AIS1, STANDARD_FALSE);

Brepprimapi_makesphere s2 (GP_PNT (0, 300, 0), 100.);

Handle (AIS_SHAPE) Asphere = New AIS_SHAPE (S2.Shape ());

m_paiscontext-> setMaRial (Asphere, Graphic3D_Nom_SILVER);

m_paiscontext-> setDisplaymode (asphere, 1);

m_paiscontext-> display (asphere);

m_pview-> fdoml ();

M_PView-> ZfitAll ();

AIS_LISTOFINTERACTIVE ALIST;

m_paiscontext-> DisplayedObjects (aliST);

AIS_ListiteratorOflistofinteractIVELISTITOTERATOR

AliStiterator.initialize (alistiterator.more (); aliistiterator.next ()) {

m_paiscontext-> remove (aliStiterator.value ());

}

Tcolgp_Array1OFPNT POINTS1 (1, 4);

Points1.SetValue (1, GP_PNT (0, 0));

Points1.setValue (2, GP_PNT (2, 1, 0));

Points1.setValue (3, GP_PNT (4, 0));

Points1.setValue (4, GP_PNT (6, 2, 0));

Geomapi_PointStobsPline PTBS1 (Points1);

Handle (geom_bsplinecurve) BSC1 = PTBS1.CURVE ();

Topods_edge s = brebuildrapi_makeedge (bsc1) .edge ();

Handle (AIS_SHAPE) AIS1 = New AIS_SHAPE (S);

m_paiscontext-> setColor (AIS1, Quantity_noc_green, standard_false);

M_paiscontext-> setMaRial (AIS1, Graphic3D_Nom_Plastic, Standard_false); m_paiscontext-> Display (AIS1, STANDARD_FALSE);

m_pview-> fdoml ();

m_pview-> zfitall (); * /

}

Void C3dWnd :: OnMousemove (uint nflags, cpoint point)

{

// Todo: add your message handler code here and / or call default

IF (NFLAGS & MK_LBUTTON)

{

IF (NFLAGS & MK_CONTROL)

{

// Move with MB1 and Control: on the dynamic zooming

// do the zoom in function of mouse's coordinates

M_PView-> Zoom (Cxmax, Cymax, Point.x, Point.y);

// save the current mouse coordinate in min

CXMAX = Point.x;

CYMAX = Point.y;

}

ELSE // IF (Ctrl)

{

Switch (m_currentmode)

{

Case curaction3d_nothing:

CXMAX = Point.x; cymax = point.y;

DrawRectangle (Cxmin, Cymin, Cxmax, Cymax, Standard_FALSE);

DrawRectangle (Cxmin, Cymin, Cxmax, Cymax, Standard_True);

Break;

Case curaction3d_dynamiczooming:

M_PView-> Zoom (Cxmax, Cymax, Point.x, Point.y);

// Save the current mouse coordinate in min / n ";

CXMAX = Point.x; cymax = point.y;

Break;

Case curaction3d_windowzooming:

CXMAX = Point.x; cymax = point.y;

DrawRectangle (Cxmin, Cymin, Cxmax, Cymax, Standard_FALSE, LONGDASH);

DrawRectangle (Cxmin, Cymin, Cxmax, Cymax, Standard_True, Longdash);

Break;

Case curaction3d_dynamicpanning:

M_PView-> Pan (Point.x-Cxmax, Cymax-Point.y); // Realize The Panning

CXMAX = Point.x; cymax = point.y;

Break;

Case curaction3d_globalpanning: // Nothing

Break;

Case Curaction3D_DynamicRotation:

M_PView-> Rotation (Point.x, Point.y);

m_pview-> redraw ();

Break;

DEFAULT:

Standard_Failure :: Raise ("Incompatible Current Mode");

Break;

}

}

}

CWnd :: OnMousemove (NFLAGS, POINT);

}

Void c3dwnd :: DrawRectangle (const standard_integer miny, const standard_integer miny,

Const Standard_integer maxx,

Const Standard_integer MAXY,

Const Standard_Boolean Draw,

Const Linestyle AlineStyle

{

Static int m_drawmode;

IF (! m_ppen && alinestyle == solid)

{m_ppen = new CPEN (ps_solid, 1, rgb (0,0,0)); m_drawmode = r2_mergepennot;}

Else if (! m_ppen&& aLineStyle == DOT)

{m_ppen = new CPEN (PS_DOT, 1, RGB (0, 0, 0)); m_drawmode = r2_xorpen;

Else if (! m_ppen& aLineStyle == shortdash)

{m_ppen = new CPEN (ps_dash, 1, rgb (255, 0)); m_drawmode = r2_xorpen;

Else if (! m_ppen& aLineStyle == longdash)

{m_ppen = new CPEN (PS_Dash, 1, RGB (0, 0, 0)); m_drawmode = r2_notxorpen;

Else IF (alinestyle == default)

{m_ppen = null; m_drawmode = r2_mergepennot;

CPEN * AOLDPEN;

CClientDC ClientDC (this);

IF (m_ppen) AOLDPEN = Clientdc.selectObject (m_ppen);

Clientdc.setrop2 (M_DrawMode);

Static Standard_integer Storedminx, StoredMaxx, StoredMiny, StoredMax;

Static standard_boolean m_isvisible;

IF (M_ISVisible &&! Draw) // Move or Up: Erase At the Old Position

{

Clientdc.moveto (StoredMinx, StoredMiny); Clientdc.Lineto (StoredMinx, StoredMax);

Clientdc.Lineto (StoredMaxx, StoredMax);

ClientDC.LineTo (StoredMaxx, StoredMiny); Clientdc.LineTo (StoredMinx, StoredMiny);

m_isvisible = false;

}

StoredMinx = min (minx, maxx);

StoredMiny = min (Miny, Maxy);

StoredMaxx = Max (minx, maxx);

StoredMaxy = Max (Miny, Maxy);

IF (DRAW) // Move: DRAW

{

Clientdc.moveto (StoredMinx, StoredMiny); Clientdc.Lineto (StoredMinx, StoredMax);

Clientdc.LineTo (StoredMaxx, StoredMax); Clientdc.Lineto (StoredMaxx, StoredMiny); Clientdc.Lineto (StoredMinx, StoredMiny);

m_isvisible = true;

}

IF (m_ppen) clientdc.selectObject (alldpen);

}

Bool C3dWnd :: OnMousewheel (Uint Nflags, Short ZDELTA, CPOINT PT)

{

// Move with MB1 and Control: on the dynamic zooming

// do the zoom in function of mouse's coordinates

M_Curzoom = m_pview-> scale ();

CXMAX = Pt.x ZDELTA / CZOOMSTEP;

Cymax = pt.y zdelta / czoomstep;

IF (Cymax <0) cymax = 0;

IF (CXMAX <0) cxmax = 0;

M_PView-> Zoom (Cxmax, Cymax, Pt.x, Pt.y);

Return True;

// Return CWnd :: OnMousewheel (NFLAGS, ZDELTA, PT);

}

Void C3dWnd :: ONLBUTTONUP (uint nflags, cpoint point)

{

IF (NFLAGS & MK_CONTROL)

{

Return;

}

ELSE // IF (Ctrl)

{

Switch (m_currentmode)

{

Case curaction3d_nothing:

IF (Point.x == Cxmin && Point.y == CYMIN)

{// no Offset Between Down and Up -> SELECTEVENT

CXMAX = Point.x;

CYMAX = Point.y;

Else

{

DrawRectangle (Cxmin, Cymin, Cxmax, Cymax, Standard_FALSE);

CXMAX = Point.x;

CYMAX = Point.y;

}

Break;

Case curaction3d_dynamiczooming:

m_currentmode = curaction3d_nothing;

Break;

Case curaction3d_windowzooming:

DrawRectangle (Cxmin, Cymin, Cxmax, Cymax, Standard_FALSE);

CXMAX = Point.x;

CYMAX = Point.y;

IF ((Cxmin-Cxmax)> Valzwmin) || (ABS (Cymin-Cymax)> Valzwmin))

{

// do the zoom window Between Pmin and PMAX

M_PView-> WindowfitAll (Cxmin, Cymin, Cxmax, Cymax);

}

m_currentmode = curaction3d_nothing;

Break;

Case curaction3d_dynamicpanning:

m_currentmode = curaction3d_nothing;

Break;

Case curaction3d_globalpanning:

M_PView-> Place (Point.x, Point.y, M_Curzoom);

m_currentmode = curaction3d_nothing;

Break;

Case Curaction3D_DynamicRotation:

m_currentmode = curaction3d_nothing;

Break;

}

}

}

Void C3dWnd :: ONLBUTTONDOWN (UINT NFLAGS, CPOINT)

{

// save the current mouse coordinate in min

CXMIN = Point.x; cymin = point.y;

CXMAX = Point.x; cymax = point.y;

IF (NFLAGS & MK_CONTROL)

{

// Button MB1 Down Control: Start Zomming

// setCursor (AFXGetApp () -> loadStandardCursor ());

}

ELSE // IF (Ctrl)

{

Switch (m_currentmode)

{

Case curaction3d_nothing: // start a DRAG

Break;

Case curaction3d_dynamiczooming:

Break;

Case curaction3d_windowzooming:

Break;

Case curaction3d_dynamicpanning:

Break;

Case curaction3d_globalpanning:

Break;

Case Curaction3D_DynamicRotation:

IF (! m_degenerateemodeison)

M_PView-> setdegenerateModeon ();

M_PView-> Startrotation (Point.x, Point.y);

Break;

Case Curaction3d_BeginPositionAllight:

Break;

Case curaction3d_beginspotlight:

Break;

Case curaction3d_targetspotlight:

Break;

Case Curaction3D_ENDSPOTLIGHT:

Break;

Case Curaction3D_BegindirectionAllight:

Break;

Case Curaction3D_ENDDIRECTIONALLIGHT:

Break;

}

}

CWnd :: ONLBUTTONDOWN (NFLAGS, POINT);

}

Void c3dwnd :: zooLall ()

{

m_pview-> fdoml ();

M_PView-> ZfitAll ();

}

Void C3dWnd :: zoomwin ()

{

m_currentmode = curaction3d_windowzooming;

}

Void C3dWnd :: zoomprog ()

{

m_currentmode = curaction3d_dynamiczooming;

}

Void C3dWnd :: Pan ()

{

m_currentmode = curaction3d_dynamicpanning;

}

Void c3dwnd :: panglobal ()

{

M_Curzoom = m_pview-> scale ();

// Do a global zoom

// myview-> fdoml ();

m_currentmode = curaction3d_globalpanning;

}

Void C3dWnd :: Rotate ()

{

m_currentmode = curaction3d_dynamicrotation;}

Void c3dwnd :: hideon ()

{

M_PView-> setdegenerateModeoff ();

m_degenerateemodeison = standard_false;

}

Void C3dWnd :: Hideoff ()

{

M_PView-> setdegenerateModeon ();

m_degeneratemodeison = standard_true;

}

Void C3dWnd :: AXO ()

{

m_pview-> setProj (v3d_xposynegzpos);

}

Void c3dwnd :: back ()

{

m_pview-> setproj (v3d_xneg);

}

Void c3dwnd :: bottom ()

{

m_pview-> setproj (v3d_zneg);

}

Void C3dWnd :: Front ()

{

M_PView-> setProj (v3d_xpos);

}

Void c3dwnd :: left ()

{

m_pview-> setproj (v3d_ypos);

}

Void c3dwnd :: top ()

{

M_PView-> setProj (v3d_zpos);

}

Void C3dWnd :: Right ()

{

m_pview-> setproj (v3d_yneg);

}

Void c3dwnd :: clear ()

{

AIS_LISTOFINTERACTIVE ALIST;

m_paiscontext-> DisplayedObjects (aliST);

AIS_ListiteratorOflistofinteractIVELISTITOTERATOR

AliStiterator.initialize (alistiterator.more (); aliistiterator.next ()) {

m_paiscontext-> remove (aliStiterator.value ());

}

}

Void C3dWnd :: Refresh ()

{

Clear ();

Displayaxis ();

}

Void C3dWnd :: DisplayAxis ()

{

Handle (AIS_TRIHEDRON) ATRIHEDRON

Handle (geom_axis2placement) anaxis = new geom_axis2placement (gp :: xoy ());

Atrihedron = new AIS_TRIHEDRON (Anaxis);

m_paiscontext-> Display (atrihedron);

}

Void C3dWnd :: DispplayText ()

{

/ *

TCOLLECTION_EXTENDEDSTRING TEXT ("Test");

Handle (Sample2D_Text) ATEXT =

New Sample2D_text (text,

140, 15 * (J-5), // ANX, Any

Ask_tot_solid, // atype

0.0, // anangle

0.0, // aslant

Color , // acolorindex

2, // afondex

J / 10, // ascale

Standard_false, // aisunderline

Standard_true, // aiszoomable

Graphic2d_toa_topleft; // atypeofalignmentMyaisinteractiveContext2D-> Display (atext, // Object

Standard_false); // redraw

IF (color == my2dviewer-> colorMap () -> size ()) color = 1; * /

}

Void C3dWnd :: ShowSolid (const Int Nid)

{

Clear ();

Topods_Solid Solid = GetSolidByid (NID);

Handle (AIS_SHAPE) AIS = New AIS_SHAPE (SOLID);

m_paiscontext-> setColor (AIS, Quantity_noc_green, Standard_false);

m_paiscontext-> setmaterial (AIS, Graphic3D_Nom_GOLD, STANDARD_FALSE);

m_paiscontext-> setDisplayMode (AIS, 1);

m_paiscontext-> Display (AIS, STANDARD_FALSE);

m_pview-> fdoml ();

M_PView-> ZfitAll ();

}

Void C3dWnd :: Showface (unsigned long nfaceid)

{

Clear ();

Topods_face face;

Getfacebyid (NfaceID, Face);

Handle (AIS_SHAPE) AIS = New AIS_SHAPE (FACE);

m_paiscontext-> setColor (AIS, Quantity_noc_gray99, Standard_false);

m_paiscontext-> setmaterial (AIS, Graphic3D_Nom_stone, Standard_false);

m_paiscontext-> setDisplayMode (AIS, 1);

m_paiscontext-> Display (AIS, STANDARD_FALSE);

m_pview-> fdoml ();

M_PView-> ZfitAll ();

}

2, ctest3dviewdlg class

/

// // Test3DViewDLG.H: Header File

Class C3dWnd;

Class Ctest3DViewdlg: Public CDialog

{

// construction

PUBLIC:

CTest3DViewDLG (CWND * PParent = NULL); // Standard Constructionor

~ Ctest3dviewdlg ();

// Dialog Data

// {{AFX_DATA (CTEST3DVIEWDLG)

ENUM {IDD = IDD_TEST3DVIEW_DIALOG};

// Note: The Classwizard Will Add Data MEMBERS Here

//}} AFX_DATA

// ClassWizard Generated Virtual Function Overrides

// {{AFX_VIRTUAL (CTEST3DVIEWDLG)

protected:

Virtual Void DodataExchange (CDataExchange * PDX); // DDX / DDV Support

//}} AFX_VIRTUAL

// Implementation

protected:

Hicon M_Hicon;

// generated message map functions

// {{AFX_MSG (ctest3dviewDLG) Virtual Bool OnInitdialog ();

AFX_MSG Void OnSysCommand (Uint Nid, LParam Lparam);

AFX_MSG void onpaint ();

AFX_MSG HCURSOR ONQUERYDRAGICON ();

Virtual void onok ();

AFX_MSG Void OnbtnshowVolume ();

AFX_MSG Void Onbtnzoomall ();

AFX_MSG Bool OnMousewheel (Uint Nflags, Short Zdelta, Cpoint Pt);

AFX_MSG void onbtnzoomwin ();

AFX_MSG void onbtnzoomprog ();

AFX_MSG void onbtnpan ();

AFX_MSG Void OnbtnPanglobal ();

AFX_MSG void onbtnrotate ();

AFX_MSG void Onbtnhideon ();

AFX_MSG Void OnbtnHideoff ();

AFX_MSG void onbtnfront ();

AFX_MSG void OnbtNTOP ();

AFX_MSG void onbtnleft ();

AFX_MSG Void OnbtnRight ();

AFX_MSG void OnbtnBack ();

AFX_MSG Void Onbtnbottom ();

AFX_MSG void onbtnaxo ();

AFX_MSG void onbtnloaddata ();

AFX_MSG void OnbtnBoolean ();

AFX_MSG Void OnbtndisPlay ();

AFX_MSG void OnbtnBoolean2 ();

//}} AFX_MSG

Declare_message_map ()

Private:

C3dWnd * m_p3dwnd;

}

// Test3DViewdlg.cpp: importation file

//

#include "stdafx.h"

#include "test3dview.h"

#include "test3dviewdlg.h"

#include "../3dviewdll/3dwnd.h"

#include "loading" loadDatadlg.h "

#include "boildlg.h"

#include "displaydlg.h"

#include "boolfacecutdlg.h"

#ifdef _Debug

#define new debug_new

#undef this_file

Static char this_file [] = __file__;

#ENDIF

/

// Caboutdlg Dialog Used for App About

Class Caboutdlg: Public CDIALOG

{

PUBLIC:

Caboutdlg ();

// Dialog Data

// {{AFX_DATA (Caboutdlg)

Enum {IDD = IDD_ABOUTBOX};

//}} AFX_DATA

// ClassWizard Generated Virtual Function Overrides

// {{AFX_VIRTUAL (caboutdlg)

protected:

Virtual Void DodataExchange (CDataExchange * PDX); // DDX / DDV Support

//}} AFX_VIRTUAL

// Implementation

protected:

/ {{AFX_MSG (caboutdlg) //}} AFX_MSG

Declare_message_map ()

}

Caboutdlg :: Caboutdlg (): cdialog (Caboutdlg :: IDD)

{

// {{AFX_DATA_INIT (Caboutdlg)

//}} AFX_DATA_INIT

}

Void Caboutdlg :: DODATAEXCHANGE (CDataExchange * PDX)

{

CDIALOG :: DODATAEXCHANGE (PDX);

// {{AFX_DATA_MAP (Caboutdlg)

//}} AFX_DATA_MAP

}

Begin_MESSAGE_MAP (Caboutdlg, CDIALOG)

// {{AFX_MSG_MAP (Caboutdlg)

// no message Handlers

//}} AFX_MSG_MAP

END_MESSAGE_MAP ()

/

// ctest3dviewdlg dialog

CTest3DViewdlg :: ctest3dviewdlg (cWnd * pParent / * = null * /)

: Cdialog (ctest3dviewdlg :: idd, pparent)

{

// {{AFX_DATA_INIT (CTEST3DVIEWDLG)

// Note: The classwizard will add member initialization here

//}} AFX_DATA_INIT

// Note That Loadicon Does Not Require a Subsequent Destroyicon in Win32

m_hicon = AFXGetApp () -> loadicon (iDR_mainframe);

m_p3dwnd = null;

}

CTest3DViewdlg :: ~ ctest3dviewdlg ()

{

IF (m_p3dwnd! = null)

DELETE M_P3DWND;

}

Void ctest3dviewdlg :: DODATAEXCHANGE (CDATAEXCHANGE * PDX)

{

CDIALOG :: DODATAEXCHANGE (PDX);

// {{AFX_DATA_MAP (CTEST3DVIEWDLG)

// Note: The Classwizard Will Add Ddx and DDV Calls Here

//}} AFX_DATA_MAP

}

Begin_MESSAGE_MAP (CTEST3DVIEWDLG, CDIALOG)

// {{AFX_MSG_MAP (ctest3dviewDLG)

ON_WM_SYSCOMMAND ()

ON_WM_PAINT ()

ON_WM_QUERYDRAGICON ()

ON_BN_CLICKED (IDC_BTN_SHOWVOLUME, ONBTNSHOWVOLUME)

ON_BN_CLICKED (IDC_BTN_ZoomAll, Onbtnzoomall)

ON_WM_MOUSEWHEEL ()

ON_BN_CLICKED (IDC_BTN_Zoomwin, Onbtnzoomwin)

ON_BN_CLICKED (IDC_BTN_ZoomProg, OnbtnZoomprog)

ON_BN_CLICKED (IDC_BTN_PAN, ONBTNPAN)

ON_BN_CLICKED (IDC_BTN_PANGLOBAL, ONBTNPANGLOBAL)

ON_BN_CLICKED (IDC_BTN_ROTATE, ONBTNROTATE)

ON_BN_CLICKED (IDC_BTN_HIDEON, ONBTNHIDEON)

ON_BN_CLICKED (IDC_BTN_HIDEOFF, ONBTNHIDEOFF)

ON_BN_CLICKED (IDC_BTN_FRONT, ONBTNFRONT)

ON_BN_CLICKED (IDC_BTN_TOP, ONBTNTOP) ON_BN_CLICKED (IDC_BTN_LEFT, ONBTNLEFT)

ON_BN_CLICKED (IDC_BTN_RIGHT, ONBTNRIGHT)

ON_BN_CLICKED (IDC_BTN_BACK, ONBTNBACK)

ON_BN_CLICKED (iDC_BTN_BOTTOM, ONBTNBOTTOM)

ON_BN_CLICKED (IDC_BTN_AXO, ONBTNAXO)

ON_BN_CLICKED (IDC_BTN_LOADDATA, ONBTNLOADDATA)

ON_BN_CLICKED (IDC_BTN_BOOLEAN, ONBTNBOOLEAN)

ON_BN_CLICKED (IDC_BTN_DISPLAY, ONBTNDISPLAY)

ON_BN_CLICKED (IDC_BTN_BOOLEAN2, ONBTNBOOLEAN2)

//}} AFX_MSG_MAP

END_MESSAGE_MAP ()

/

// ctest3dviewdlg message handlers

Bool ctest3dviewdlg :: oninitdialog ()

{

CDIALOG :: OnInitdialog ();

// Add "About ..." Menu Item to System Menu.

// IDM_AboutBox Must Be in The System Command Range.

Assert (IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

Assert (IDM_AboutBox <0xF000);

CMenu * psysmenu = getSystemMenu (false);

IF (psysmenu! = NULL)

{

CSTRING STRABOUTMENU;

STRABOUTMENU.LOADSTRING (IDS_ABOUTBOX);

IF (! straboutmenu.isempty ())

{

Psysmenu-> appendmenu (mf_separator);

Psysmenu-> appendmenu (mf_string, idm_aboutbox, straboutmenu);

}

}

// set the icon for this dialog. The framework does this AutomaticL

// when the application's main window is not a dialog

Seticon (M_Hicon, True); // set Big icon

Seticon (M_Hicon, False); // set small icon

// Todo: Add Extra Initialization Here

m_p3dwnd = new c3dwnd;

CRECT RECT;

/ *

CWND * PWND = NULL;

PWND = getdlgitem (IDC_3DWND);

ASSERT (PWND);

PWND-> getClientRect (Rect); * /

M_p3dWnd-> Create (NULL, "TEST3D", WS_CHILD | WS_VISIBLE, RECT, this, ID_3DVIEWER);

Return True; // Return True UnsS you set the focus to a control

}

Void ctest3dviewdlg :: oversyscommand (uint nid, lparam lparam)

{

IF ((NID & 0xFFF0) == IDM_ABOUTBOX) {

Caboutdlg dlgabout;

DLGAbout.domodal ();

}

Else

{

CDIALOG :: OnSysCommand (NID, LPARAM);

}

}

// if you add a minimize button to your dialog, you will need the code below

// to draw the icon. For mfc Applications Using The Document / View Model,

// this is automatic or done for you by the framework.

Void ctest3dviewdlg :: onpaint ()

{

IF (Isiconic ())

{

CPAINTDC DC (this); // Device Context for Painting

SendMessage (WM_ICONERASEBKGND, (WPARAM) dc.getsafehdc (), 0);

// Center icon in Client Rectangle

INT CXCION = GetSystemMetrics;

INT Cyicon = GetSystemMetrics (SM_CYICON);

CRECT RECT;

GetClientRect (& RECT);

INT x = (Rect.width () - CXICON 1) / 2;

INT Y = (Rect.height () - Cyicon 1) / 2;

// Draw the icon

Dc.drawicon (X, Y, M_HICON);

}

Else

{

CDIALOG :: onpaint ();

}

CRECT RECT;

CWND * PWND = NULL;

PWND = getdlgitem (IDC_3DWND);

ASSERT (PWND);

PWND-> getClientRect (RECT);

IF (m_p3dwnd! = null)

M_p3dWnd-> MoveWindow (RECT);

}

// the system calls this to obtain the cursor to display while the user DRAGS

// the minimized window.

Hcursor ctest3dviewdlg :: ONQUERYDRAGICON ()

{

Return (hcursor) m_hicon;

}

Void ctest3dviewdlg :: onok ()

{

// Todo: Add extra validation here

CDIALOG :: Onok ();

}

Void ctest3dviewdlg :: OnbtnshowVolume ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> showvolume ();

}

Void ctest3dviewdlg :: onbtnzoomall ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> zooLAll ();

}

Bool ctest3dviewdlg :: onmousewheel (uint nflags, short zdelta, cpoint pt)

{

// Todo: add your message handler code here and / or call defaultwparam wparam;

LParam Lparam;

WPARAM = MakewParam (nflags, zdelta); // We can put whatver we

LParam = makelparam (pt.x, pt.y); // Want In WPARAM & LPARAM

IF (m_p3dwnd! = null)

Return m_p3dWnd-> SendMessage (WM_Mousewheel, WPARAM, LPARAM);

Return CDIALOG :: OnMousewheel (NFLAGS, ZDELTA, PT);

}

Void ctest3dviewdlg :: onbtnzoomwin ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> zoomwin ();

}

Void ctest3dviewdlg :: OnbtnZoomprog ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

M_p3dWnd-> zoomprog ();

}

Void ctest3dviewdlg :: onbtnpan ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> PAN ();

}

Void ctest3dviewdlg :: OnbtNPANGLOBAL ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> panglobal ();

}

Void ctest3dviewdlg :: onbtnrotate ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> rotate ();

}

Void ctest3dviewdlg :: Onbtnhideon ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> hideon ();

}

Void ctest3dviewdlg :: OnbTnHideoff ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> hideoff ();

}

Void ctest3dviewdlg :: onbtnfront ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> front ();

}

Void ctest3dviewdlg :: OnbtNTOP ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dWnd-> TOP ();

}

Void ctest3dviewdlg :: onbtnleft ()

{

// Todo: Add Your Control Notification Handler Code Hered (m_p3dwnd);

m_p3dwnd-> left ();

}

Void ctest3dviewdlg :: OnbtnRight ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> right ();

}

Void ctest3dviewdlg :: Onbtnback ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> back ();

}

Void ctest3dviewdlg :: onbtnbottom ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dwnd-> bottom ();

}

Void ctest3dviewdlg :: onbtnaxo ()

{

// Todo: Add Your Control Notification Handler Code Here

Assert (m_p3dwnd);

m_p3dWnd-> AXO ();

}

Void ctest3dviewdlg :: onbtnloaddata ()

{

// Todo: Add Your Control Notification Handler Code Here

Cloaddatadlg DLG (this);

Dlg.domodal ();

}

Void ctest3dviewdlg :: OnbtnBoolean ()

{

// Todo: Add Your Control Notification Handler Code Here

CBOOLDLG DLG;

Dlg.domodal ();

}

Void ctest3dviewdlg :: onbtndisplay ()

{

// Todo: Add Your Control Notification Handler Code Here

CDisPlayDLG DLG;

Dlg.domodal ();

Assert (m_p3dwnd);

IF (DLG.M_NID <0) Return;

IF (DLG.M_BFACE) {

m_p3dwnd-> showface (dlg.m_nid);

} else {

m_p3dWnd-> showSolid (DLG.M_NID);

}

}

Void ctest3dviewdlg :: OnbtnBoolean2 ()

{

// Todo: Add Your Control Notification Handler Code Here

CBoolFacecutdlg DLG;

Dlg.domodal ();

}

If You Want The Sourece Codes, Write Down Your Email As Below.

转载请注明原文地址:https://www.9cbs.com/read-66619.html

New Post(0)