Moved more functionality out of the project.

This commit is contained in:
leo 2014-11-25 00:51:34 +00:00
parent 28a030dd9a
commit deabf0524a
7 changed files with 225 additions and 200 deletions

View file

@ -692,6 +692,64 @@ void lcModel::CalculateStep()
mLights[LightIdx]->UpdatePosition(mCurrentStep);
}
void lcModel::ShowFirstStep()
{
if (mCurrentStep == 1)
return;
mCurrentStep = 1;
CalculateStep();
UpdateSelection();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
gMainWindow->UpdateCurrentStep();
}
void lcModel::ShowLastStep()
{
lcStep LastStep = GetLastStep();
if (mCurrentStep == LastStep)
return;
mCurrentStep = LastStep;
CalculateStep();
UpdateSelection();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
gMainWindow->UpdateCurrentStep();
}
void lcModel::ShowPreviousStep()
{
if (mCurrentStep == 1)
return;
mCurrentStep--;
CalculateStep();
UpdateSelection();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
gMainWindow->UpdateCurrentStep();
}
void lcModel::ShowNextStep()
{
if (mCurrentStep == LC_STEP_MAX)
return;
mCurrentStep++;
CalculateStep();
UpdateSelection();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
gMainWindow->UpdateCurrentStep();
}
lcStep lcModel::GetLastStep() const
{
lcStep Step = 1;
@ -702,6 +760,52 @@ lcStep lcModel::GetLastStep() const
return Step;
}
void lcModel::InsertStep()
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
Piece->InsertTime(mCurrentStep, 1);
if (Piece->IsSelected() && !Piece->IsVisible(mCurrentStep))
Piece->SetSelected(false);
}
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
mCameras[CameraIdx]->InsertTime(mCurrentStep, 1);
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
mLights[LightIdx]->InsertTime(mCurrentStep, 1);
SaveCheckpoint(tr("Inserting Step"));
CalculateStep();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
UpdateSelection();
}
void lcModel::RemoveStep()
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
Piece->RemoveTime(mCurrentStep, 1);
if (Piece->IsSelected() && !Piece->IsVisible(mCurrentStep))
Piece->SetSelected(false);
}
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
mCameras[CameraIdx]->RemoveTime(mCurrentStep, 1);
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
mLights[LightIdx]->RemoveTime(mCurrentStep, 1);
SaveCheckpoint(tr("Removing Step"));
CalculateStep();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
UpdateSelection();
}
lcGroup* lcModel::AddGroup(const char* Prefix, lcGroup* Parent)
{
lcGroup* Group = new lcGroup();
@ -775,7 +879,7 @@ void lcModel::GroupSelection()
}
}
SaveCheckpoint("Grouping");
SaveCheckpoint(tr("Grouping"));
}
void lcModel::UngroupSelection()
@ -818,7 +922,7 @@ void lcModel::UngroupSelection()
SelectedGroups.DeleteAll();
RemoveEmptyGroups();
SaveCheckpoint("Ungrouping");
SaveCheckpoint(tr("Ungrouping"));
}
void lcModel::AddSelectedPiecesToGroup()
@ -852,7 +956,7 @@ void lcModel::AddSelectedPiecesToGroup()
}
RemoveEmptyGroups();
SaveCheckpoint("Grouping");
SaveCheckpoint(tr("Grouping"));
}
void lcModel::RemoveFocusPieceFromGroup()
@ -869,7 +973,7 @@ void lcModel::RemoveFocusPieceFromGroup()
}
RemoveEmptyGroups();
SaveCheckpoint("Ungrouping");
SaveCheckpoint(tr("Ungrouping"));
}
void lcModel::ShowEditGroupsDialog()
@ -920,7 +1024,7 @@ void lcModel::ShowEditGroupsDialog()
if (Modified)
{
ClearSelection(true);
SaveCheckpoint("Editing Groups");
SaveCheckpoint(tr("Editing Groups"));
}
}
@ -2282,7 +2386,7 @@ void lcModel::ShowArrayDialog()
}
AddToSelection(NewPieces);
SaveCheckpoint("Array");
SaveCheckpoint(tr("Array"));
}
void lcModel::ShowMinifigDialog()
@ -2319,7 +2423,7 @@ void lcModel::ShowMinifigDialog()
}
SetSelection(Pieces);
SaveCheckpoint("Minifig");
SaveCheckpoint(tr("Minifig"));
}
void lcModel::Export3DStudio() const

View file

@ -150,6 +150,13 @@ public:
return mCurrentStep;
}
void ShowFirstStep();
void ShowLastStep();
void ShowPreviousStep();
void ShowNextStep();
void InsertStep();
void RemoveStep();
lcGroup* AddGroup(const char* Prefix, lcGroup* Parent);
lcGroup* GetGroup(const char* Name, bool CreateIfMissing);
void RemoveGroup(lcGroup* Group);

View file

@ -2030,100 +2030,29 @@ void Project::HandleCommand(LC_COMMANDS id)
break;
}
case LC_VIEW_TIME_NEXT:
{
if (mCurrentStep == LC_STEP_MAX)
break;
case LC_VIEW_TIME_NEXT:
ShowNextStep();
break;
mCurrentStep++;
case LC_VIEW_TIME_PREVIOUS:
ShowPreviousStep();
break;
CalculateStep();
UpdateSelection();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
gMainWindow->UpdateCurrentStep();
} break;
case LC_VIEW_TIME_FIRST:
ShowFirstStep();
break;
case LC_VIEW_TIME_PREVIOUS:
{
if (mCurrentStep == 1)
break;
mCurrentStep--;
case LC_VIEW_TIME_LAST:
ShowLastStep();
break;
CalculateStep();
UpdateSelection();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
gMainWindow->UpdateCurrentStep();
} break;
case LC_VIEW_TIME_INSERT:
InsertStep();
break;
case LC_VIEW_TIME_FIRST:
{
mCurrentStep = 1;
CalculateStep();
UpdateSelection();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
gMainWindow->UpdateCurrentStep();
} break;
case LC_VIEW_TIME_LAST:
{
mCurrentStep = GetLastStep();
CalculateStep();
UpdateSelection();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
gMainWindow->UpdateCurrentStep();
} break;
case LC_VIEW_TIME_INSERT:
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
Piece->InsertTime(mCurrentStep, 1);
if (Piece->IsSelected() && !Piece->IsVisible(mCurrentStep))
Piece->SetSelected(false);
}
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
mCameras[CameraIdx]->InsertTime(mCurrentStep, 1);
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
mLights[LightIdx]->InsertTime(mCurrentStep, 1);
CheckPoint("Adding Step");
CalculateStep();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
UpdateSelection();
} break;
case LC_VIEW_TIME_DELETE:
{
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
lcPiece* Piece = mPieces[PieceIdx];
Piece->RemoveTime(mCurrentStep, 1);
if (Piece->IsSelected() && !Piece->IsVisible(mCurrentStep))
Piece->SetSelected(false);
}
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
mCameras[CameraIdx]->RemoveTime(mCurrentStep, 1);
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
mLights[LightIdx]->RemoveTime(mCurrentStep, 1);
CheckPoint("Removing Step");
CalculateStep();
gMainWindow->UpdateFocusObject(GetFocusObject());
gMainWindow->UpdateAllViews();
UpdateSelection();
} break;
case LC_VIEW_TIME_DELETE:
RemoveStep();
break;
case LC_VIEW_VIEWPOINT_FRONT:
gMainWindow->GetActiveView()->SetViewpoint(LC_VIEWPOINT_FRONT);
@ -2153,51 +2082,28 @@ void Project::HandleCommand(LC_COMMANDS id)
gMainWindow->GetActiveView()->SetViewpoint(LC_VIEWPOINT_HOME);
break;
case LC_VIEW_CAMERA_NONE:
case LC_VIEW_CAMERA1:
case LC_VIEW_CAMERA2:
case LC_VIEW_CAMERA3:
case LC_VIEW_CAMERA4:
case LC_VIEW_CAMERA5:
case LC_VIEW_CAMERA6:
case LC_VIEW_CAMERA7:
case LC_VIEW_CAMERA8:
case LC_VIEW_CAMERA9:
case LC_VIEW_CAMERA10:
case LC_VIEW_CAMERA11:
case LC_VIEW_CAMERA12:
case LC_VIEW_CAMERA13:
case LC_VIEW_CAMERA14:
case LC_VIEW_CAMERA15:
case LC_VIEW_CAMERA16:
{
View* ActiveView = gMainWindow->GetActiveView();
lcCamera* Camera = NULL;
case LC_VIEW_CAMERA_NONE:
gMainWindow->GetActiveView()->RemoveCamera();
break;
if (id == LC_VIEW_CAMERA_NONE)
{
Camera = ActiveView->mCamera;
if (!Camera->IsSimple())
{
ActiveView->SetCamera(Camera, true);
Camera = ActiveView->mCamera;
}
}
else
{
if (id - LC_VIEW_CAMERA1 < mCameras.GetSize())
{
Camera = mCameras[id - LC_VIEW_CAMERA1];
ActiveView->SetCamera(Camera, false);
}
else
break;
}
gMainWindow->UpdateCurrentCamera(mCameras.FindIndex(ActiveView->mCamera));
gMainWindow->UpdateAllViews();
} break;
case LC_VIEW_CAMERA1:
case LC_VIEW_CAMERA2:
case LC_VIEW_CAMERA3:
case LC_VIEW_CAMERA4:
case LC_VIEW_CAMERA5:
case LC_VIEW_CAMERA6:
case LC_VIEW_CAMERA7:
case LC_VIEW_CAMERA8:
case LC_VIEW_CAMERA9:
case LC_VIEW_CAMERA10:
case LC_VIEW_CAMERA11:
case LC_VIEW_CAMERA12:
case LC_VIEW_CAMERA13:
case LC_VIEW_CAMERA14:
case LC_VIEW_CAMERA15:
case LC_VIEW_CAMERA16:
gMainWindow->GetActiveView()->SetCameraIndex(id - LC_VIEW_CAMERA1);
break;
case LC_VIEW_CAMERA_RESET:
{
@ -2226,64 +2132,16 @@ void Project::HandleCommand(LC_COMMANDS id)
gMainWindow->DoDialog(LC_DIALOG_CHECK_UPDATES, NULL);
break;
case LC_HELP_ABOUT:
{
String Info;
char Text[256];
case LC_HELP_ABOUT:
gMainWindow->DoDialog(LC_DIALOG_ABOUT, NULL);
gMainWindow->GetActiveView()->MakeCurrent();
GLint Red, Green, Blue, Alpha, Depth, Stencil;
GLboolean DoubleBuffer, RGBA;
glGetIntegerv(GL_RED_BITS, &Red);
glGetIntegerv(GL_GREEN_BITS, &Green);
glGetIntegerv(GL_BLUE_BITS, &Blue);
glGetIntegerv(GL_ALPHA_BITS, &Alpha);
glGetIntegerv(GL_DEPTH_BITS, &Depth);
glGetIntegerv(GL_STENCIL_BITS, &Stencil);
glGetBooleanv(GL_DOUBLEBUFFER, &DoubleBuffer);
glGetBooleanv(GL_RGBA_MODE, &RGBA);
Info = "OpenGL Version ";
Info += (const char*)glGetString(GL_VERSION);
Info += "\n";
Info += (const char*)glGetString(GL_RENDERER);
Info += " - ";
Info += (const char*)glGetString(GL_VENDOR);
sprintf(Text, "\n\nColor Buffer: %d bits %s %s", Red + Green + Blue + Alpha, RGBA ? "RGBA" : "indexed", DoubleBuffer ? "double buffered" : "");
Info += Text;
sprintf(Text, "\nDepth Buffer: %d bits", Depth);
Info += Text;
sprintf(Text, "\nStencil Buffer: %d bits", Stencil);
Info += Text;
Info += "\nGL_ARB_vertex_buffer_object extension: ";
Info += GL_HasVertexBufferObject() ? "supported" : "not supported";
Info += "\nGL_ARB_framebuffer_object extension: ";
Info += GL_HasFramebufferObjectARB() ? "supported" : "not supported";
Info += "\nGL_EXT_framebuffer_object extension: ";
Info += GL_HasFramebufferObjectEXT() ? "supported" : "not supported";
Info += "\nGL_EXT_texture_filter_anisotropic extension: ";
if (GL_SupportsAnisotropic)
{
sprintf(Text, "supported (max %d)", (int)GL_MaxAnisotropy);
Info += Text;
}
else
Info += "not supported";
gMainWindow->DoDialog(LC_DIALOG_ABOUT, (char*)Info);
} break;
case LC_VIEW_TIME_ADD_KEYS:
gMainWindow->SetAddKeys(!gMainWindow->GetAddKeys());
break;
case LC_VIEW_TIME_ADD_KEYS:
gMainWindow->SetAddKeys(!gMainWindow->GetAddKeys());
break;
case LC_EDIT_SNAP_RELATIVE:
{
lcPreferences& Preferences = lcGetPreferences();
Preferences.SetForceGlobalTransforms(!Preferences.mForceGlobalTransforms);
} break;
lcGetPreferences().SetForceGlobalTransforms(!lcGetPreferences().mForceGlobalTransforms);
break;
case LC_EDIT_LOCK_X:
gMainWindow->SetLockX(!gMainWindow->GetLockX());

View file

@ -36,6 +36,21 @@ View::~View()
delete mCamera;
}
void View::RemoveCamera()
{
if (mCamera && mCamera->IsSimple())
return;
lcCamera* Camera = mCamera;
mCamera = new lcCamera(true);
if (Camera)
mCamera->CopyPosition(Camera);
gMainWindow->UpdateCurrentCamera(-1);
Redraw();
}
void View::SetCamera(lcCamera* Camera, bool ForceCopy)
{
if (Camera->IsSimple() || ForceCopy)
@ -54,6 +69,20 @@ void View::SetCamera(lcCamera* Camera, bool ForceCopy)
}
}
void View::SetCameraIndex(int Index)
{
const lcArray<lcCamera*>& Cameras = mProject->GetCameras();
if (Index >= Cameras.GetSize())
return;
lcCamera* Camera = Cameras[Index];
SetCamera(Camera, false);
gMainWindow->UpdateCurrentCamera(Index);
Redraw();
}
void View::SetViewpoint(lcViewpoint Viewpoint)
{
if (!mCamera || !mCamera->IsSimple())

View file

@ -76,7 +76,9 @@ public:
void EndPieceDrag(bool Accept);
void ZoomExtents();
void RemoveCamera();
void SetCamera(lcCamera* Camera, bool ForceCopy);
void SetCameraIndex(int Index);
void SetViewpoint(lcViewpoint Viewpoint);
void SetDefaultCamera();
lcMatrix44 GetProjectionMatrix() const;

View file

@ -1,6 +1,8 @@
#include "lc_global.h"
#include "lc_qaboutdialog.h"
#include "ui_lc_qaboutdialog.h"
#include "lc_mainwindow.h"
#include "preview.h"
lcQAboutDialog::lcQAboutDialog(QWidget *parent, void *data) :
QDialog(parent),
@ -8,10 +10,35 @@ lcQAboutDialog::lcQAboutDialog(QWidget *parent, void *data) :
{
ui->setupUi(this);
options = (char*)data;
ui->version->setText(tr("LeoCAD Version %1").arg(QString::fromLatin1(LC_VERSION_TEXT)));
ui->version->setText(QString(tr("LeoCAD Version ")) + LC_VERSION_TEXT);
ui->info->setText(options);
gMainWindow->mPreviewWidget->MakeCurrent();
GLint Red, Green, Blue, Alpha, Depth, Stencil;
GLboolean DoubleBuffer, RGBA;
glGetIntegerv(GL_RED_BITS, &Red);
glGetIntegerv(GL_GREEN_BITS, &Green);
glGetIntegerv(GL_BLUE_BITS, &Blue);
glGetIntegerv(GL_ALPHA_BITS, &Alpha);
glGetIntegerv(GL_DEPTH_BITS, &Depth);
glGetIntegerv(GL_STENCIL_BITS, &Stencil);
glGetBooleanv(GL_DOUBLEBUFFER, &DoubleBuffer);
glGetBooleanv(GL_RGBA_MODE, &RGBA);
QString VersionFormat = tr("OpenGL Version %1\n%2 - %3\n\n");
QString Version = VersionFormat.arg(QString((const char*)glGetString(GL_VERSION)), QString((const char*)glGetString(GL_RENDERER)), QString((const char*)glGetString(GL_VENDOR)));
QString BuffersFormat = tr("Color Buffer: %1 bits %2 %3\nDepth Buffer: %4 bits\nStencil Buffer: %5 bits\n\n");
QString Buffers = BuffersFormat.arg(QString::number(Red + Green + Blue + Alpha), RGBA ? "RGBA" : tr("indexed"), DoubleBuffer ? tr("double buffered") : QString(), QString::number(Depth), QString::number(Stencil));
QString ExtensionsFormat = tr("GL_ARB_vertex_buffer_object extension: %1\nGL_ARB_framebuffer_object extension: %2\nGL_EXT_framebuffer_object extension: %3\nGL_EXT_texture_filter_anisotropic extension: %4\n");
QString VertexBufferObject = GL_HasVertexBufferObject() ? tr("Supported") : tr("Not supported");
QString FramebufferObjectARB = GL_HasFramebufferObjectARB() ? tr("Supported") : tr("Not supported");
QString FramebufferObjectEXT = GL_HasFramebufferObjectEXT() ? tr("Supported") : tr("Not supported");
QString Anisotropic = GL_SupportsAnisotropic ? tr("Supported (max %d)").arg(QString::number(GL_MaxAnisotropy)) : tr("Not supported");
QString Extensions = ExtensionsFormat.arg(VertexBufferObject, FramebufferObjectARB, FramebufferObjectEXT, Anisotropic);
ui->info->setText(Version + Buffers + Extensions);
}
lcQAboutDialog::~lcQAboutDialog()

View file

@ -15,8 +15,6 @@ public:
explicit lcQAboutDialog(QWidget *parent, void *data);
~lcQAboutDialog();
char* options;
private:
Ui::lcQAboutDialog *ui;
};