// Copyright (C) 2008 Steven Katic
#pragma once
#include "Scene.h"
#include "MouseTranslationController.h"
namespace GLDemo {
using namespace System;
using namespace System::IO;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Text;
using namespace System::Drawing;
using namespace System::Globalization;
using namespace glRenderer;
using namespace AxisIconAssembly;
using namespace FileViewerTypes;
using namespace GeometryInterface;
using namespace Types;//poor naming! it actually provides the PluginServices.
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
AxisTripod^ m_TransformGadget;
//m_TransformGadget = gcnew AxisTripod(1, Vector3::Zero());
#pragma region Translation Controller Code
///
/// <summary>
///
///
MouseTranslationController^ translationController;
Scene^ m_scene; // the one and only world drawn in OpenglViewport^ m_OpenglView
OpenglViewport^ m_OpenglView; // the one and only view
// Keep track mouse position and the 3D collision point the mouse pointer is Unprojected
// to on a 3D object when it is picked
Vector3^ m_Mouse2DPos;
Vector3^ m_Mouse3DPickPos;
bool MoveSelection;
bool PickSelection;
// Bells and whistles: a user option to draw a reprentation of the plane (and its normal)
// that is used by the translationController in the ray-plane intersection test
static bool ShowPlane = false;
property Vector3^ Mouse2DPosition
{
Vector3^ get(){ return m_Mouse2DPos; }
void set(Vector3^ v)
{
m_Mouse2DPos->X = v->X;
m_Mouse2DPos->Y = v->Y;
m_Mouse2DPos->Z = v->Z;
}
}
property Vector3^ Mouse3DPickPosition
{
Vector3^ get(){ return m_Mouse3DPickPos;}
void set(Vector3^ value)
{
m_Mouse3DPickPos = gcnew Vector3(value->X,value->Y,value->Z);
}
}
void DrawView()
{
m_OpenglView->DrawFrame();
if(PickSelection)
{
PickAnObject();
InitTranslationController();
// switch picking off
PickSelection = false;
// we do not render this pass if the user doesn't want to see objects rendered in color coded form for picking
if(m_OpenglView->RenderMode ^ (DWORD)SceneRenderMode::PickGLModel)
return;
}
m_OpenglView->DrawGrid();
m_scene->DrawSceneMeshes(m_OpenglView->RenderMode);
m_OpenglView->DrawAxisIcon();
if(ShowPlane)
{
if(m_scene->SelectionSetSize > 0)
if(MoveSelection)
translationController->DrawPlane();
}
m_OpenglView->SwapOpenGLBuffers();
UpdateStatusBar();
}
void UpdateTranslationController()
{
translationController->Update((int)Mouse2DPosition->X,(int)Mouse2DPosition->Y);
}
void InitTranslationController()
{
if(m_scene->PickedModel != nullptr)
translationController->Initialize((int)Mouse2DPosition->X,(int)Mouse2DPosition->Y,m_CurTransformationAxes,Mouse3DPickPosition);
}
void PickAnObject()
{
m_scene->DrawObjectsInPickMode();
array<unsigned char>^ color = GetPixelColorAnd3DPosition(Mouse3DPickPosition,(int)Mouse2DPosition->X,(int)Mouse2DPosition->Y);
m_scene->SelectPickedModelByColor(color, m_OpenglView->TranformGadget);
}
///
/// GetPixelColorAnd3DPosition() returns the current 3d position and color of the 2D pixel at (x,y)
/// using the current viewport, projection and modelview data that defines our (camera's)
/// view into the 3D world. It is only used to pick objects in 3D space.
/// Computer system color resolution needs to be set to High (32 bit Color) for color picking.
array<unsigned char>^ GetPixelColorAnd3DPosition(Vector3^ positionOut,int x, int y)
{
//glDisable(GL_TEXTURE_2D);
static int updatecnt = 0;
static GLint viewport[4];
static GLdouble modelview[16];
static GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glGetIntegerv(GL_VIEWPORT, viewport);
GLubyte pixel[3];
winX = (float)x;
winY = (float)viewport[3] - (float)y;
glReadBuffer( GL_BACK );
//read color
glReadPixels(x, int(winY),1,1,GL_RGB,GL_UNSIGNED_BYTE,(void *)pixel);
glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
positionOut->X = (float)posX;
positionOut->Y = (float)posZ;
positionOut->Z = (float)posY;
array<unsigned char>^ color = gcnew array<unsigned char>(3);
color[0] = pixel[0];
color[1] = pixel[1];
color[2] = pixel[2];
return color;
}
#pragma endregion
private: static CameraState m_CamState = CameraState::Off;
private: static EditMode m_EditMode = EditMode::Off;
private: static DWORD m_CurTransformationAxes = XYTRANS;
static PluginServices^ Plugins = gcnew PluginServices();
Types::AvailablePlugin^ m_selectedPlugin;
// The file name filter string which determines the choices that appear
// in the "Files of type" box of the OpenFileDialog() dialog box in file open
// and/or file import(to be implemented) mode.
String^ fileImportFilter;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::ToolStrip^ toolStripCamera;
private: System::Windows::Forms::ToolStripLabel^ toolStripCameraLabel;
private: System::Windows::Forms::ToolStripButton^ toolStripCamZoomButton;
private: System::Windows::Forms::ToolStripButton^ toolStripCamRotateButton;
private: System::Windows::Forms::ToolStripButton^ toolStripCamPanButton;
private: System::Windows::Forms::ToolStrip^ toolStrip1;
private: System::Windows::Forms::ToolStripLabel^ toolStripLabel1;
private: System::Windows::Forms::ToolStripButton^ toolStripSelectButton;
private: System::Windows::Forms::ToolStripButton^ toolStripMoveButton;
private: System::Windows::Forms::ToolStripButton^ toolStripRotateButton;
private: System::Windows::Forms::ToolStripSplitButton^ toolStripAxisSelectButton;
private: System::Windows::Forms::ToolStripMenuItem^ ToolStripXYMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ ToolStripXMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ ToolStripYMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ ToolStripZMenuItem;
private: System::Windows::Forms::StatusStrip^ statusStrip1;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusXLabel;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusYLabel;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusZLabel;
private: System::Windows::Forms::ContextMenuStrip^ viewContextMenuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ smoothHighlightsToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ wireframeToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ vertexPointsToolStripMenuItem;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator1;
private: System::Windows::Forms::ToolStripMenuItem^ viewsToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ frontToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ backToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ leftToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ rightToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ topToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ bottomToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ perspectiveToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ userToolStripMenuItem;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator2;
private: System::Windows::Forms::ToolStripMenuItem^ showGridToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ toolStripZXMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ toolStripYZMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ newToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ showPlaneToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ openToolStripMenuItem;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel1;
private: System::Windows::Forms::ToolStripMenuItem^ pickingColorCodeToolStripMenuItem;
void UpdateStatusBar()
{
//String^ TStr = " 0.0f ";
//TStr = String::Format(CultureInfo::CurrentCulture,"{0:F}",timerresult);
//toolStripStatusXLabel->Text = "timer: " + 100/Math::Ceiling(timerresult/1000000);//milliseconds
//toolStripStatusXLabel->Text = "timer: " + timerresult;
//toolStripStatusXLabel->Text = "X: " + translationController->Position->X;
//toolStripStatusYLabel->Text = "Y: " + translationController->Position->Y;
//toolStripStatusZLabel->Text = "Z: " + translationController->Position->Z;
//
toolStripStatusXLabel->Text = "X: " + translationController->Displacement->X;
toolStripStatusYLabel->Text = "Y: " + translationController->Displacement->Y;
toolStripStatusZLabel->Text = "Z: " + translationController->Displacement->Z;
//
//toolStripStatusXLabel->Text = "X: " + translationController->NextPosition->X;
//toolStripStatusYLabel->Text = "Y: " + translationController->NextPosition->Y;
//toolStripStatusZLabel->Text = "Z: " + translationController->NextPosition->Z;
}
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
m_Mouse2DPos = Vector3::Zero();
m_Mouse3DPickPos = Vector3::Zero();
PickSelection = false;
MoveSelection = false;
InitializeOpenGLComponent();
m_scene = gcnew Scene();
translationController = gcnew MouseTranslationController();
OpenGLDemo::Global::GLEngine->InitialiseGLCAPS();
}
void InitializeOpenGLComponent()
{
m_OpenglView = gcnew OpenglViewport(10,10,Width-35,Height-55-22);
m_OpenglView->Projection = ViewportProjection::Perspective;
m_OpenglView->CameraOrientation = gcnew Vector3(3.0f,0.0f,0.0f);
m_OpenglView->CameraPosition = gcnew Vector3(0.0f,0.0f,10.0f);
m_OpenglView->ViewPosition = ViewportPosition::Perspective;
m_OpenglView->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::view1_MouseDown);
m_OpenglView->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::view1_MouseMove);
m_OpenglView->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::view1_MouseUp);
this->Controls->Add(this->m_OpenglView);
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
m_OpenglView->ReleaseResources();
m_scene->ClearModels();
}
private: System::Windows::Forms::Timer^ timer1;
protected:
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->openToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->newToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripCamera = (gcnew System::Windows::Forms::ToolStrip());
this->toolStripCameraLabel = (gcnew System::Windows::Forms::ToolStripLabel());
this->toolStripCamZoomButton = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripCamRotateButton = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripCamPanButton = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
this->toolStripLabel1 = (gcnew System::Windows::Forms::ToolStripLabel());
this->toolStripSelectButton = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripMoveButton = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripRotateButton = (gcnew System::Windows::Forms::ToolStripButton());
this->toolStripAxisSelectButton = (gcnew System::Windows::Forms::ToolStripSplitButton());
this->ToolStripXMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->ToolStripYMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->ToolStripZMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->ToolStripXYMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripZXMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripYZMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
this->toolStripStatusLabel1 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->toolStripStatusXLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->toolStripStatusYLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->toolStripStatusZLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->viewContextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->smoothHighlightsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->wireframeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->vertexPointsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->pickingColorCodeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->viewsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->frontToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->backToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->leftToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->rightToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->topToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->bottomToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->perspectiveToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->userToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->showGridToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->showPlaneToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->menuStrip1->SuspendLayout();
this->toolStripCamera->SuspendLayout();
this->toolStrip1->SuspendLayout();
this->statusStrip1->SuspendLayout();
this->viewContextMenuStrip1->SuspendLayout();
this->SuspendLayout();
//
// timer1
//
this->timer1->Enabled = true;
this->timer1->Interval = 1;
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->fileToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(704, 24);
this->menuStrip1->TabIndex = 0;
this->menuStrip1->Text = L"menuStrip1";
//
// fileToolStripMenuItem
//
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->openToolStripMenuItem,
this->newToolStripMenuItem});
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
this->fileToolStripMenuItem->Text = L"&File";
//
// openToolStripMenuItem
//
this->openToolStripMenuItem->Name = L"openToolStripMenuItem";
this->openToolStripMenuItem->Size = System::Drawing::Size(103, 22);
this->openToolStripMenuItem->Text = L"&Open";
this->openToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::openToolStripMenuItem_Click);
//
// newToolStripMenuItem
//
this->newToolStripMenuItem->Name = L"newToolStripMenuItem";
this->newToolStripMenuItem->Size = System::Drawing::Size(103, 22);
this->newToolStripMenuItem->Text = L"&New";
this->newToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::newToolStripMenuItem_Click);
//
// toolStripCamera
//
this->toolStripCamera->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->toolStripCameraLabel,
this->toolStripCamZoomButton, this->toolStripCamRotateButton, this->toolStripCamPanButton});
this->toolStripCamera->Location = System::Drawing::Point(0, 24);
this->toolStripCamera->Name = L"toolStripCamera";
this->toolStripCamera->Size = System::Drawing::Size(704, 25);
this->toolStripCamera->TabIndex = 1;
this->toolStripCamera->Text = L"toolStrip1";
//
// toolStripCameraLabel
//
this->toolStripCameraLabel->Font = (gcnew System::Drawing::Font(L"Segoe UI", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->toolStripCameraLabel->Name = L"toolStripCameraLabel";
this->toolStripCameraLabel->Size = System::Drawing::Size(48, 22);
this->toolStripCameraLabel->Text = L"Camera";
//
// toolStripCamZoomButton
//
this->toolStripCamZoomButton->CheckOnClick = true;
this->toolStripCamZoomButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripCamZoomButton->Font = (gcnew System::Drawing::Font(L"Segoe UI", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->toolStripCamZoomButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripCamZoomButton.Image")));
this->toolStripCamZoomButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripCamZoomButton->Name = L"toolStripCamZoomButton";
this->toolStripCamZoomButton->Size = System::Drawing::Size(23, 22);
this->toolStripCamZoomButton->Text = L"Zoom Camera";
this->toolStripCamZoomButton->CheckedChanged += gcnew System::EventHandler(this, &Form1::toolStripCamZoomButton_CheckedChanged);
//
// toolStripCamRotateButton
//
this->toolStripCamRotateButton->CheckOnClick = true;
this->toolStripCamRotateButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripCamRotateButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripCamRotateButton.Image")));
this->toolStripCamRotateButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripCamRotateButton->Name = L"toolStripCamRotateButton";
this->toolStripCamRotateButton->Size = System::Drawing::Size(23, 22);
this->toolStripCamRotateButton->Text = L"Rotate Camera";
this->toolStripCamRotateButton->CheckedChanged += gcnew System::EventHandler(this, &Form1::toolStripCamRotateButton_CheckedChanged);
//
// toolStripCamPanButton
//
this->toolStripCamPanButton->CheckOnClick = true;
this->toolStripCamPanButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripCamPanButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripCamPanButton.Image")));
this->toolStripCamPanButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripCamPanButton->Name = L"toolStripCamPanButton";
this->toolStripCamPanButton->Size = System::Drawing::Size(23, 22);
this->toolStripCamPanButton->Text = L"Pan Camera";
this->toolStripCamPanButton->CheckedChanged += gcnew System::EventHandler(this, &Form1::toolStripCamPanButton_CheckedChanged);
//
// toolStrip1
//
this->toolStrip1->ImageScalingSize = System::Drawing::Size(20, 20);
this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->toolStripLabel1,
this->toolStripSelectButton, this->toolStripMoveButton, this->toolStripRotateButton, this->toolStripAxisSelectButton});
this->toolStrip1->Location = System::Drawing::Point(0, 49);
this->toolStrip1->Name = L"toolStrip1";
this->toolStrip1->Size = System::Drawing::Size(704, 27);
this->toolStrip1->TabIndex = 2;
this->toolStrip1->Text = L"toolStrip1";
//
// toolStripLabel1
//
this->toolStripLabel1->Font = (gcnew System::Drawing::Font(L"Segoe UI", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->toolStripLabel1->Name = L"toolStripLabel1";
this->toolStripLabel1->Size = System::Drawing::Size(47, 24);
this->toolStripLabel1->Text = L"Objects";
this->toolStripLabel1->ToolTipText = L"Objects";
//
// toolStripSelectButton
//
this->toolStripSelectButton->CheckOnClick = true;
this->toolStripSelectButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripSelectButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripSelectButton.Image")));
this->toolStripSelectButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripSelectButton->Name = L"toolStripSelectButton";
this->toolStripSelectButton->Size = System::Drawing::Size(24, 24);
this->toolStripSelectButton->Text = L"Select Object";
this->toolStripSelectButton->CheckedChanged += gcnew System::EventHandler(this, &Form1::toolStripSelectButton_CheckedChanged);
//
// toolStripMoveButton
//
this->toolStripMoveButton->CheckOnClick = true;
this->toolStripMoveButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripMoveButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripMoveButton.Image")));
this->toolStripMoveButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripMoveButton->Name = L"toolStripMoveButton";
this->toolStripMoveButton->Size = System::Drawing::Size(24, 24);
this->toolStripMoveButton->Text = L"Move Object";
this->toolStripMoveButton->CheckedChanged += gcnew System::EventHandler(this, &Form1::toolStripMoveButton_CheckedChanged);
//
// toolStripRotateButton
//
this->toolStripRotateButton->CheckOnClick = true;
this->toolStripRotateButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripRotateButton->Enabled = false;
this->toolStripRotateButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripRotateButton.Image")));
this->toolStripRotateButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripRotateButton->Name = L"toolStripRotateButton";
this->toolStripRotateButton->Size = System::Drawing::Size(24, 24);
this->toolStripRotateButton->Text = L"Rotate";
this->toolStripRotateButton->CheckedChanged += gcnew System::EventHandler(this, &Form1::toolStripRotateButton_CheckedChanged);
//
// toolStripAxisSelectButton
//
this->toolStripAxisSelectButton->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(6) {this->ToolStripXMenuItem,
this->ToolStripYMenuItem, this->ToolStripZMenuItem, this->ToolStripXYMenuItem, this->toolStripZXMenuItem, this->toolStripYZMenuItem});
this->toolStripAxisSelectButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripAxisSelectButton.Image")));
this->toolStripAxisSelectButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripAxisSelectButton->Name = L"toolStripAxisSelectButton";
this->toolStripAxisSelectButton->Size = System::Drawing::Size(160, 24);
this->toolStripAxisSelectButton->Text = L"Transform In XY Plane";
this->toolStripAxisSelectButton->DropDownItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &Form1::toolStripAxisSelectButton_DropDownItemClicked);
//
// ToolStripXMenuItem
//
this->ToolStripXMenuItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"ToolStripXMenuItem.Image")));
this->ToolStripXMenuItem->Name = L"ToolStripXMenuItem";
this->ToolStripXMenuItem->Size = System::Drawing::Size(191, 22);
this->ToolStripXMenuItem->Text = L"Transform in X Axis";
//
// ToolStripYMenuItem
//
this->ToolStripYMenuItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"ToolStripYMenuItem.Image")));
this->ToolStripYMenuItem->Name = L"ToolStripYMenuItem";
this->ToolStripYMenuItem->Size = System::Drawing::Size(191, 22);
this->ToolStripYMenuItem->Text = L"Transform in Y Axis";
//
// ToolStripZMenuItem
//
this->ToolStripZMenuItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"ToolStripZMenuItem.Image")));
this->ToolStripZMenuItem->Name = L"ToolStripZMenuItem";
this->ToolStripZMenuItem->Size = System::Drawing::Size(191, 22);
this->ToolStripZMenuItem->Text = L"Transform in Z Axis";
//
// ToolStripXYMenuItem
//
this->ToolStripXYMenuItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"ToolStripXYMenuItem.Image")));
this->ToolStripXYMenuItem->Name = L"ToolStripXYMenuItem";
this->ToolStripXYMenuItem->Size = System::Drawing::Size(191, 22);
this->ToolStripXYMenuItem->Text = L"Transform in XY Plane";
//
// toolStripZXMenuItem
//
this->toolStripZXMenuItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripZXMenuItem.Image")));
this->toolStripZXMenuItem->Name = L"toolStripZXMenuItem";
this->toolStripZXMenuItem->Size = System::Drawing::Size(191, 22);
this->toolStripZXMenuItem->Text = L"Transform in ZX Plane";
//
// toolStripYZMenuItem
//
this->toolStripYZMenuItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripYZMenuItem.Image")));
this->toolStripYZMenuItem->Name = L"toolStripYZMenuItem";
this->toolStripYZMenuItem->Size = System::Drawing::Size(191, 22);
this->toolStripYZMenuItem->Text = L"Transform in YZ Plane";
//
// statusStrip1
//
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->toolStripStatusLabel1,
this->toolStripStatusXLabel, this->toolStripStatusYLabel, this->toolStripStatusZLabel});
this->statusStrip1->Location = System::Drawing::Point(0, 562);
this->statusStrip1->Name = L"statusStrip1";
this->statusStrip1->Size = System::Drawing::Size(704, 22);
this->statusStrip1->TabIndex = 3;
this->statusStrip1->Text = L"statusStrip1";
//
// toolStripStatusLabel1
//
this->toolStripStatusLabel1->Name = L"toolStripStatusLabel1";
this->toolStripStatusLabel1->Size = System::Drawing::Size(157, 17);
this->toolStripStatusLabel1->Text = L"Ray Plane Intersection Point:";
//
// toolStripStatusXLabel
//
this->toolStripStatusXLabel->Name = L"toolStripStatusXLabel";
this->toolStripStatusXLabel->Size = System::Drawing::Size(44, 17);
this->toolStripStatusXLabel->Text = L"X: 0.0";
//
// toolStripStatusYLabel
//
this->toolStripStatusYLabel->Name = L"toolStripStatusYLabel";
this->toolStripStatusYLabel->Size = System::Drawing::Size(44, 17);
this->toolStripStatusYLabel->Text = L"Y: 0.0";
//
// toolStripStatusZLabel
//
this->toolStripStatusZLabel->Name = L"toolStripStatusZLabel";
this->toolStripStatusZLabel->Size = System::Drawing::Size(44, 17);
this->toolStripStatusZLabel->Text = L"Z: 0.0";
//
// viewContextMenuStrip1
//
this->viewContextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(9) {this->smoothHighlightsToolStripMenuItem,
this->wireframeToolStripMenuItem, this->vertexPointsToolStripMenuItem, this->pickingColorCodeToolStripMenuItem, this->toolStripSeparator1,
this->viewsToolStripMenuItem, this->toolStripSeparator2, this->showGridToolStripMenuItem, this->showPlaneToolStripMenuItem});
this->viewContextMenuStrip1->Name = L"contextMenuStrip1";
this->viewContextMenuStrip1->ShowCheckMargin = true;
this->viewContextMenuStrip1->ShowImageMargin = false;
this->viewContextMenuStrip1->Size = System::Drawing::Size(186, 170);
this->viewContextMenuStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &Form1::viewContextMenuStrip1_ItemClicked);
//
// smoothHighlightsToolStripMenuItem
//
this->smoothHighlightsToolStripMenuItem->CheckOnClick = true;
this->smoothHighlightsToolStripMenuItem->Name = L"smoothHighlightsToolStripMenuItem";
this->smoothHighlightsToolStripMenuItem->Size = System::Drawing::Size(185, 22);
this->smoothHighlightsToolStripMenuItem->Text = L"&Smooth + Highlights";
//
// wireframeToolStripMenuItem
//
this->wireframeToolStripMenuItem->CheckOnClick = true;
this->wireframeToolStripMenuItem->Name = L"wireframeToolStripMenuItem";
this->wireframeToolStripMenuItem->Size = System::Drawing::Size(185, 22);
this->wireframeToolStripMenuItem->Text = L"&Wireframe";
//
// vertexPointsToolStripMenuItem
//
this->vertexPointsToolStripMenuItem->CheckOnClick = true;
this->vertexPointsToolStripMenuItem->Name = L"vertexPointsToolStripMenuItem";
this->vertexPointsToolStripMenuItem->Size = System::Drawing::Size(185, 22);
this->vertexPointsToolStripMenuItem->Text = L"&Vertex Points";
//
// pickingColorCodeToolStripMenuItem
//
this->pickingColorCodeToolStripMenuItem->CheckOnClick = true;
this->pickingColorCodeToolStripMenuItem->Name = L"pickingColorCodeToolStripMenuItem";
this->pickingColorCodeToolStripMenuItem->Size = System::Drawing::Size(185, 22);
this->pickingColorCodeToolStripMenuItem->Text = L"&Picking Color Code";
//
// toolStripSeparator1
//
this->toolStripSeparator1->Name = L"toolStripSeparator1";
this->toolStripSeparator1->Size = System::Drawing::Size(182, 6);
//
// viewsToolStripMenuItem
//
this->viewsToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(8) {this->frontToolStripMenuItem,
this->backToolStripMenuItem, this->leftToolStripMenuItem, this->rightToolStripMenuItem, this->topToolStripMenuItem, this->bottomToolStripMenuItem,
this->perspectiveToolStripMenuItem, this->userToolStripMenuItem});
this->viewsToolStripMenuItem->Name = L"viewsToolStripMenuItem";
this->viewsToolStripMenuItem->Size = System::Drawing::Size(185, 22);
this->viewsToolStripMenuItem->Text = L"&Views";
this->viewsToolStripMenuItem->DropDownItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &Form1::viewsToolStripMenuItem_DropDownItemClicked);
this->viewsToolStripMenuItem->DropDownOpening += gcnew System::EventHandler(this, &Form1::viewsToolStripMenuItem_DropDownOpening);
//
// frontToolStripMenuItem
//
this->frontToolStripMenuItem->Name = L"frontToolStripMenuItem";
this->frontToolStripMenuItem->Size = System::Drawing::Size(134, 22);
this->frontToolStripMenuItem->Text = L"&Front";
//
// backToolStripMenuItem
//
this->backToolStripMenuItem->Name = L"backToolStripMenuItem";
this->backToolStripMenuItem->Size = System::Drawing::Size(134, 22);
this->backToolStripMenuItem->Text = L"&Back";
//
// leftToolStripMenuItem
//
this->leftToolStripMenuItem->Name = L"leftToolStripMenuItem";
this->leftToolStripMenuItem->Size = System::Drawing::Size(134, 22);
this->leftToolStripMenuItem->Text = L"&Left";
//
// rightToolStripMenuItem
//
this->rightToolStripMenuItem->Name = L"rightToolStripMenuItem";
this->rightToolStripMenuItem->Size = System::Drawing::Size(134, 22);
this->rightToolStripMenuItem->Text = L"&Right";
//
// topToolStripMenuItem
//
this->topToolStripMenuItem->Name = L"topToolStripMenuItem";
this->topToolStripMenuItem->Size = System::Drawing::Size(134, 22);
this->topToolStripMenuItem->Text = L"&Top";
//
// bottomToolStripMenuItem
//
this->bottomToolStripMenuItem->Name = L"bottomToolStripMenuItem";
this->bottomToolStripMenuItem->Size = System::Drawing::Size(134, 22);
this->bottomToolStripMenuItem->Text = L"Bo&ttom";
//
// perspectiveToolStripMenuItem
//
this->perspectiveToolStripMenuItem->Name = L"perspectiveToolStripMenuItem";
this->perspectiveToolStripMenuItem->Size = System::Drawing::Size(134, 22);
this->perspectiveToolStripMenuItem->Text = L"&Perspective";
//
// userToolStripMenuItem
//
this->userToolStripMenuItem->Name = L"userToolStripMenuItem";
this->userToolStripMenuItem->Size = System::Drawing::Size(134, 22);
this->userToolStripMenuItem->Text = L"&User";
//
// toolStripSeparator2
//
this->toolStripSeparator2->Name = L"toolStripSeparator2";
this->toolStripSeparator2->Size = System::Drawing::Size(182, 6);
//
// showGridToolStripMenuItem
//
this->showGridToolStripMenuItem->CheckOnClick = true;
this->showGridToolStripMenuItem->Name = L"showGridToolStripMenuItem";
this->showGridToolStripMenuItem->Size = System::Drawing::Size(185, 22);
this->showGridToolStripMenuItem->Text = L"Show &Grid";
//
// showPlaneToolStripMenuItem
//
this->showPlaneToolStripMenuItem->Name = L"showPlaneToolStripMenuItem";
this->showPlaneToolStripMenuItem->Size = System::Drawing::Size(185, 22);
this->showPlaneToolStripMenuItem->Text = L"Show &Plane";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(704, 584);
this->Controls->Add(this->statusStrip1);
this->Controls->Add(this->toolStrip1);
this->Controls->Add(this->toolStripCamera);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"Form1";
this->Text = L"GLDemo";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->Resize += gcnew System::EventHandler(this, &Form1::Form1_Resize);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->toolStripCamera->ResumeLayout(false);
this->toolStripCamera->PerformLayout();
this->toolStrip1->ResumeLayout(false);
this->toolStrip1->PerformLayout();
this->statusStrip1->ResumeLayout(false);
this->statusStrip1->PerformLayout();
this->viewContextMenuStrip1->ResumeLayout(false);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private:Void LoadFile(String^ path)
{
path = path->ToLower();
FileInfo^ fileInfo = gcnew FileInfo(path);
if (fileInfo->Exists == false)
{
MessageBox::Show("File doesn't exist " + path,"LoadFile MSG");
return;
}
//See if a plugin is available to do the importing for us
m_selectedPlugin = Plugins->AvailablePlugins->FindByExtSupport(fileInfo->Extension);
if(m_selectedPlugin != nullptr)
{
LoadFileUsingPlugin(path,m_selectedPlugin);
}
else
{
MessageBox::Show("Plugin not available for" + path,"LoadFile MSG");
}
}
private: System::Void LoadFileUsingPlugin(String^ path, Types::AvailablePlugin^ selectedPlugin)
{
Cursor->Current = Cursors::WaitCursor;
List<IModel^>^ modelList = gcnew List<IModel^>();
Model^ spawner = gcnew Model();
modelList->Add(spawner);
selectedPlugin->Instance->DoImport(path,spawner);
for(int m = 0; m < modelList->Count; m++)
{
Model^ model = (Model^)modelList[m];
if (model->MeshCount <= 0)
{
MessageBox::Show("No mesh in model" ,"LoadFile MSG");
modelList->Remove(model);
//break;
}
else
{
if (model->VertexList->Count > 0)
{
model->ComputeNormals();
model->CalcBoundingVolumes();
model->LoadMaterials();
// stores model data in a VBO if available
model->CreateMeshBuffersGL(IS_VERTEX_BUFFER_SUPPORTED);
// use the following to not use a VBO at all
//model->CreateMeshBuffersGL(false);
if(m_scene)
{
m_scene->LoadModel(model);
}
}
}
}
modelList->Clear();
UseWaitCursor = false;
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
DrawView();
}
private: System::Void view1_MouseDown(System::Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e)
{
ProcessMouseDown(e);
}
private: System::Void view1_MouseUp(System::Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e)
{
ProcessMouseUp(e);
}
private: System::Void view1_MouseMove(System::Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e)
{
ProcessMouseMove(e);
}
private: System::Void ProcessMouseDown(System::Windows::Forms::MouseEventArgs^ e)
{
Mouse2DPosition = gcnew Vector3((float)e->X,(float)e->Y,(float)0);
if ( e->Button == ::MouseButtons::Left )
{
if(m_CamState != CameraState::Off)
{
SetCamState(true);
}
else if (m_EditMode != EditMode::Off)
{
SetEditMode(true);
}
}
if ( e->Button == ::MouseButtons::Right )
{
viewContextMenuStrip1_UpdateCheckedItems(m_OpenglView->RenderMode);
m_OpenglView->ContextMenuStrip = this->viewContextMenuStrip1;
}
// Update the view: rapid movements of the mouse and pressing of the left mouse button
// seems to prevent PickAnObject() from being processed properly in the render loop
// Cause: ? possible loss of a tick in the timer or gl context for a milli sec or 2!?
DrawView();
}
private: System::Void ProcessMouseUp(System::Windows::Forms::MouseEventArgs^ e)
{
if ( e->Button == ::MouseButtons::Left )
{
SetCamState(false);
SetEditMode(false);
}
}
private: System::Void ProcessMouseMove(System::Windows::Forms::MouseEventArgs^ e)
{
int x = e->X;
int y = e->Y;
Mouse2DPosition = gcnew Vector3((float)e->X,(float)e->Y,(float)0);
if(m_CamState != CameraState::Off)
{
CameraModeMouseMove(x,y);
}
else if (m_EditMode != EditMode::Off)
{
EditModeMouseMove(x,y);
}
}
private: System::Void CameraModeMouseMove(int x,int y)
{
switch (m_CamState)
{
case CameraState::ZoomOn:
{
m_OpenglView->Zoom(y);
} break;
case CameraState::RotationOn:
{
m_OpenglView->Rotate(x,y);
} break;
case CameraState::PanOn:
{
m_OpenglView->Pan(x,y);
} break;
default:
{
} break;
}
}
private: System::Void EditModeMouseMove(int x, int y)
{
switch (m_EditMode)
{
case EditMode::Select:
{
// TO DO:
} break;
case EditMode::SelectAndMove:
{
if(MoveSelection)
{
UpdateTranslationController();
m_scene->MoveSelectionSetDelta(translationController->Displacement);
}
//
//m_scene->MoveSelectionSet(translationController->Position);
} break;
case EditMode::Rotate://SelectAndRotate
{
//m_scene->RotateSelectionSet(x,y,m_OpenglView->Width,m_OpenglView->Height);
} break;
default:
{
} break;
}
}
private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
OpenFileDialog^ ofd = gcnew OpenFileDialog;
ofd->CheckFileExists = true;
ofd->Filter = fileImportFilter;
ofd->FilterIndex = 0;
if (ofd->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
try
{
LoadFile(ofd->FileName);
}
catch (Exception^ ex)
{
MessageBox::Show(ex->Message + "\r\n\r\n" + ex->ToString(), "Error",
MessageBoxButtons::OK,
MessageBoxIcon::Error);
// ex = nullptr;
// MessageBox::Show("File cannot be Loaded:\n" + ofd->FileName , "Message");
}
}
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
int pluginsLoaded = -1;
pluginsLoaded = Plugins->LoadPlugins(Application::StartupPath + "\\Plugins");
if(pluginsLoaded == -1)
{
MessageBox::Show("No 3D Model File Import Plugins loaded.\nMove the Plugins folder to the same directory as the GLDemo.exe executable then shutdown and restart the application.",
"No Plugins loaded");
}
//create the import filter to be dispalyed in the open/import
//file dialog(s).
fileImportFilter = CreateFilenameFilterString("import");
}
private: void SetEditMode(bool on)
{
switch (m_EditMode)
{
case EditMode::SelectAndMove:
{
m_scene->SetEditModeMoveOn(on);
PickSelection = on;
MoveSelection = on;
}break;
case EditMode::Select:
{
m_scene->SetEditModeSelectOn(on);
PickSelection = on;
}break;
default:
break;
}
}
/// <summary>
/// Set the current Camera movement parameter to active or inactive
///
private: void SetCamState(bool on)
{
switch (m_CamState)
{
case CameraState::ZoomOn:
{
m_OpenglView->ZoomCameraOn(on);
} break;
case CameraState::RotationOn:
{
m_OpenglView->RotateCameraOn(on);
} break;
case CameraState::PanOn:
{
m_OpenglView->PanCameraOn(on);
} break;
case CameraState::Off:
{
m_OpenglView->ZoomCameraOn(false);
m_OpenglView->RotateCameraOn(false);
m_OpenglView->PanCameraOn(false);
}break;
default:
{
} break;
}
}
/// <summary>
/// Creates a file name filter string, which determines the choices
/// that appear in the "Save as file type" or "Files of type" box in
/// the OpenFileDialog() dialog box. [Note: two filters (i.e. pligin types)
/// are currently supported: "import" for plugins that support the loading of
/// files with a particular file name extension and "export" for plugins that
/// support the saving of files with a particular file name extension]
/// Sample filters:
/// Filter1 = "3DS files (*.3ds)|*.3ds; |All files|*.*";
/// Filter2 = "MS3D files (*.ms3d;*.txt)|*.ms3d;*.txt|Binary MS3D files (*.ms3d)|" +
/// "*.ms3d|Text MS3D files (*.txt)|*.txt|All files|*.*";
/// </summary>
/// <param name="type">Description of the type of plugins
/// from which to obtain file extensions that will be added to the
/// file name filter string.</param>
/// <returns>The file filtering options that will be used in the
/// OpenFileDialog() dialog box.</returns>
private: String^ CreateFilenameFilterString(String^ type)
{
String^ builtFilter;
String^ sep = "|";
String^ delim = "; ";
String^ Dot = "*";
String^ OpenBckt = "(";
String^ CloseBckt = ")";
String^ AllFileTypes = "All Model Types (";
String^ AllFiles = " All Files (*.*)|*.*||";
StringBuilder^ ExtList1 = gcnew StringBuilder(); // of form "*.ms3d;", "*.3ds;",
StringBuilder^ ExtList2 = gcnew StringBuilder(); // of form "*.ms3d", "*.3ds",
//StringBuilder^ LongDescList = gcnew StringBuilder();
//
// ExtList1 CloseBckt sep
// "All Model Types (*.3ds; *.im; *.pm; *.ms3d; *.obj)|
StringBuilder^ partDesc1 = gcnew StringBuilder();
partDesc1->Append(AllFileTypes);// +test1;
// ExtList1 sep
// *.3ds; *.im; *.pm; *.ms3d; *.obj
StringBuilder^ partFilter2 = gcnew StringBuilder();
// longDesc OpenBckt ext2 CloseBckt sep ext2 sep
// 3DS Files (*.3ds)|*.3ds|Auran Jet im Files (*.im)|*.im|...
StringBuilder^ partDesc2 = gcnew StringBuilder();
int pluginfiltersAdded = 0;
for each (Types::AvailablePlugin^ pluginOn in Plugins->AvailablePlugins)
{
String^ thisPluginType = pluginOn->Instance->Type();
if (thisPluginType->Equals(type->ToLower()))
{
//
for(int extcnt = 1; extcnt <= pluginOn->Instance->ExtensionCount(); extcnt++)
{
String^ Ext = pluginOn->Instance->Extension(extcnt)->ToLower();
//String^ Ext = (pluginOn->Instance->Extension())->ToLower();
String^ LongDesc = (pluginOn->Instance->Description(extcnt))->ToLower();
String^ ext1 = Dot + Ext + delim;
String^ ext2 = Dot + Ext;
ExtList1->Append(ext1);
ExtList2->Append(ext2);
partDesc1->Append(ext1);
partFilter2->Append(ext1);
String^ LongDescPart
= LongDesc + OpenBckt + ext2 + CloseBckt + sep + ext2 + sep;
partDesc2->Append(LongDescPart);
pluginfiltersAdded++;
}
}
}
if(pluginfiltersAdded >0)
{
builtFilter = partDesc1 + CloseBckt + sep +
partFilter2 + sep + partDesc2 +
AllFiles;
}
else
{
//MessageBox::Show( "No plugin filters added" );
builtFilter = AllFiles;
}
return builtFilter->ToString();
}
private: System::Void toolStripCamZoomButton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
if (CheckState::Checked == this->toolStripCamZoomButton->CheckState)
{
// uncheck other buttons in the Camera group before setting the
// m_CamState since unchecking here calls the CheckedChanged()
// methods below and that will set m_CamState to CameraState::Off
this->toolStripCamRotateButton->CheckState = CheckState::Unchecked;
this->toolStripCamPanButton->CheckState = CheckState::Unchecked;
//..and Object group
this->toolStripMoveButton->CheckState = CheckState::Unchecked;
this->toolStripRotateButton->CheckState = CheckState::Unchecked;
this->toolStripSelectButton->CheckState = CheckState::Unchecked;
m_CamState = CameraState::ZoomOn;
}
else
{
m_CamState = CameraState::Off;
}
m_EditMode = EditMode::Off;
}
private: System::Void toolStripCamRotateButton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
if (CheckState::Checked == this->toolStripCamRotateButton->CheckState)
{
// uncheck other buttons in the Camera group
this->toolStripCamZoomButton->CheckState = CheckState::Unchecked;
this->toolStripCamPanButton->CheckState = CheckState::Unchecked;
//..and Object group
this->toolStripMoveButton->CheckState = CheckState::Unchecked;
this->toolStripRotateButton->CheckState = CheckState::Unchecked;
this->toolStripSelectButton->CheckState = CheckState::Unchecked;
m_CamState = CameraState::RotationOn;
}
else
{
m_CamState = CameraState::Off;
}
m_EditMode = EditMode::Off;
}
private: System::Void toolStripCamPanButton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
if (CheckState::Checked == this->toolStripCamPanButton->CheckState)
{
// uncheck other buttons in the Camera group
this->toolStripCamRotateButton->CheckState = CheckState::Unchecked;
this->toolStripCamZoomButton->CheckState = CheckState::Unchecked;
//..and Object group
this->toolStripMoveButton->CheckState = CheckState::Unchecked;
this->toolStripRotateButton->CheckState = CheckState::Unchecked;
this->toolStripSelectButton->CheckState = CheckState::Unchecked;
m_CamState = CameraState::PanOn;
}
else
{
m_CamState = CameraState::Off;
}
m_EditMode = EditMode::Off;
}
private: System::Void toolStripSelectButton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
if (CheckState::Checked == this->toolStripSelectButton->CheckState)
{
// uncheck other buttons in the Camera and Object groups
this->toolStripMoveButton->CheckState = CheckState::Unchecked;
this->toolStripRotateButton->CheckState = CheckState::Unchecked;
// uncheck other buttons in the Camera group
this->toolStripCamRotateButton->CheckState = CheckState::Unchecked;
this->toolStripCamZoomButton->CheckState = CheckState::Unchecked;
this->toolStripCamPanButton->CheckState = CheckState::Unchecked;
m_EditMode = EditMode::Select;
m_CamState = CameraState::Off;
}
else
{
m_EditMode = EditMode::Off;
}
}
private: System::Void toolStripMoveButton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
if (CheckState::Checked == this->toolStripMoveButton->CheckState)
{
// uncheck other buttons in the Camera group
this->toolStripRotateButton->CheckState = CheckState::Unchecked;
this->toolStripSelectButton->CheckState = CheckState::Unchecked;
//
this->toolStripCamRotateButton->CheckState = CheckState::Unchecked;
this->toolStripCamZoomButton->CheckState = CheckState::Unchecked;
this->toolStripCamPanButton->CheckState = CheckState::Unchecked;
m_EditMode = EditMode::SelectAndMove;
m_CamState = CameraState::Off;
}
else
{
m_EditMode = EditMode::Off;
}
}
private: System::Void toolStripRotateButton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
if (CheckState::Checked == this->toolStripRotateButton->CheckState)
{
// uncheck other buttons in the Camera and Object groups
this->toolStripMoveButton->CheckState = CheckState::Unchecked;
this->toolStripSelectButton->CheckState = CheckState::Unchecked;
this->toolStripCamRotateButton->CheckState = CheckState::Unchecked;
this->toolStripCamZoomButton->CheckState = CheckState::Unchecked;
this->toolStripCamPanButton->CheckState = CheckState::Unchecked;
m_EditMode = EditMode::Rotate;
m_CamState = CameraState::Off;
}
else
{
m_EditMode = EditMode::Off;
}
}
private: System::Void toolStripAxisSelectButton_DropDownItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e)
{
ToolStripItem^ item = e->ClickedItem;
m_CurTransformationAxes = this->toolStripAxisSelectButton->DropDownItems->IndexOf(item);
this->toolStripAxisSelectButton->Text = item->Text;
this->toolStripAxisSelectButton->Image = item->Image;
}
private: System::Void Form1_Resize(System::Object^ sender, System::EventArgs^ e)
{
m_OpenglView->ReSize();
}
public: void viewContextMenuStrip1_UpdateCheckedItems( DWORD renderModeState)
{
ToolStripItemCollection^ Items = viewContextMenuStrip1->Items;
for(int i = 0; i < Items->Count; i++)
{
ToolStripItem^ item = Items[i];
if(item->Equals(this->smoothHighlightsToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(renderModeState & (DWORD)SceneRenderMode::Textured)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
else if(item->Equals(this->wireframeToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(renderModeState & (DWORD)SceneRenderMode::WireModel || renderModeState & (DWORD)SceneRenderMode::WireMesh)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
else if(item->Equals(this->vertexPointsToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(renderModeState & (DWORD)SceneRenderMode::Points)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
else if(item->Equals(this->showGridToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(renderModeState & (DWORD)SceneRenderMode::ShowGrid)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
else if(item->Equals(this->showPlaneToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(ShowPlane == true)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
else if(item->Equals(this->pickingColorCodeToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(renderModeState & (DWORD)SceneRenderMode::PickGLModel)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
}
}
private: System::Void viewContextMenuStrip1_ItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e)
{
ToolStripItem^ item = e->ClickedItem;
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(item->Equals(this->smoothHighlightsToolStripMenuItem))
{
if(mi->Checked)// already on
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode ^ (DWORD)SceneRenderMode::Textured;//switch off
}
else// already off
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode | (DWORD)SceneRenderMode::Textured;//switch on
}
}
else if(item->Equals(this->wireframeToolStripMenuItem))
{
if(mi->Checked)// already on
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode ^ (DWORD)SceneRenderMode::WireModel;//switch off
}
else// already off
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode | (DWORD)SceneRenderMode::WireModel;//switch on
}
}
else if(item->Equals(this->vertexPointsToolStripMenuItem))
{
if(mi->Checked)// already on
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode ^ (DWORD)SceneRenderMode::Points;//switch off
}
else// already off
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode | (DWORD)SceneRenderMode::Points;//switch on
}
}
else if(item->Equals(this->pickingColorCodeToolStripMenuItem))
{
if(mi->Checked)// already on
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode ^ (DWORD)SceneRenderMode::PickGLModel;//switch off
}
else// already off
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode | (DWORD)SceneRenderMode::PickGLModel;//switch on
}
}
else if(item->Equals(this->showGridToolStripMenuItem))
{
if(mi->Checked)
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode ^ (DWORD)SceneRenderMode::ShowGrid;
}
else// already off
{
m_OpenglView->RenderMode = m_OpenglView->RenderMode | (DWORD)SceneRenderMode::ShowGrid;
}
}
else if(item->Equals(this->showPlaneToolStripMenuItem))
{
if(mi->Checked)
{
ShowPlane = false;
}
else// already off
{
ShowPlane = true;
}
}
}
private: System::Void viewsToolStripMenuItem_UpdateCheckedItems(DWORD viewportPosition)
{
ToolStripItemCollection^ Items = viewsToolStripMenuItem->DropDownItems;
for(int i = 0; i < Items->Count; i++)
{
ToolStripItem^ item = Items[i];
if(item->Equals(this->frontToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(viewportPosition ==(DWORD)ViewportPosition::Front)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
if(item->Equals(this->backToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(viewportPosition == (DWORD)ViewportPosition::Back)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
if(item->Equals(this->leftToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(viewportPosition == (DWORD)ViewportPosition::Left)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
if(item->Equals(this->rightToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(viewportPosition == (DWORD)ViewportPosition::Right)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
if(item->Equals(this->bottomToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(viewportPosition & (DWORD)ViewportPosition::Bottom)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
if(item->Equals(this->topToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(viewportPosition == (DWORD)ViewportPosition::Top)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
if(item->Equals(this->perspectiveToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(viewportPosition == (DWORD)ViewportPosition::Perspective)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
if(item->Equals(this->userToolStripMenuItem))
{
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(item);
if(viewportPosition == (DWORD)ViewportPosition::User)
mi->CheckState = CheckState::Checked;
else
mi->CheckState = CheckState::Unchecked;
}
}
}
private: System::Void viewsToolStripMenuItem_DropDownOpening(System::Object^ sender, System::EventArgs^ e)
{
viewsToolStripMenuItem_UpdateCheckedItems((DWORD)m_OpenglView->ViewPosition);
}
private: System::Void viewsToolStripMenuItem_DropDownItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e)
{
ToolStripItem^ itemCur = e->ClickedItem;
ToolStripMenuItem^ mi = (ToolStripMenuItem^)(itemCur);
if(mi->Checked)// already on
return;
if(mi->Equals(this->frontToolStripMenuItem))
{
m_OpenglView->ViewPosition = ViewportPosition::Front;
}
else if(mi->Equals(this->backToolStripMenuItem))
{
m_OpenglView->ViewPosition = ViewportPosition::Back;
}
else if(mi->Equals(this->leftToolStripMenuItem))
{
m_OpenglView->ViewPosition = ViewportPosition::Left;
}
else if(mi->Equals(this->rightToolStripMenuItem))
{
m_OpenglView->ViewPosition = ViewportPosition::Right;
}
else if(mi->Equals(this->topToolStripMenuItem))
{
m_OpenglView->ViewPosition = ViewportPosition::Top;
}
else if(mi->Equals(this->bottomToolStripMenuItem))
{
m_OpenglView->ViewPosition = ViewportPosition::Bottom;
}
else if(mi->Equals(this->perspectiveToolStripMenuItem))
{
m_OpenglView->ViewPosition = ViewportPosition::Perspective;
}
else if(mi->Equals(this->userToolStripMenuItem))
{
m_OpenglView->ViewPosition = ViewportPosition::User;
}
ViewportPosition curViewPos = m_OpenglView->ViewPosition;
m_OpenglView->Reset(curViewPos);
//update the actual UI
viewsToolStripMenuItem_UpdateCheckedItems((DWORD)m_OpenglView->ViewPosition);
}
private: System::Void newToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
m_scene->ClearModels();
//DrawView();
}
};
}