Skip to content

Commit

Permalink
Merge pull request #19 from Lt-Henry/issue_7
Browse files Browse the repository at this point in the history
Issue 7+9
  • Loading branch information
threedeyes authored Jan 4, 2022
2 parents 69c75c7 + 034addc commit 931e301
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 120 deletions.
1 change: 1 addition & 0 deletions STLApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
#define MSG_APPEND_REFS_RECIEVED 'APRR'
#define MSG_INPUT_VALUE_UPDATED 'IVUP'
#define MSG_INPUT_OK 'IWOK'
#define MSG_INPUT_CANCEL 'IWKO'
#define MSG_EASTER_EGG 'EEGG'
#define MSG_POPUP_MENU 'POPM'
#define MSG_APP_QUIT 'QAPP'
Expand Down
30 changes: 25 additions & 5 deletions STLInputWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

STLInputWindow::STLInputWindow(const char* title, uint32 count, BWindow* target, uint32 messageId)
: BWindow(BRect(0, 0, 640, 480), title, B_FLOATING_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_CLOSABLE),
fParentWindow(target),
fTargetMessenger(target),
fValues(count),
Expand All @@ -50,7 +50,7 @@ STLInputWindow::STLInputWindow(const char* title, uint32 count, BWindow* target,
fOkButton = new BButton(B_TRANSLATE("OK"), new BMessage(MSG_INPUT_OK));
fOkButton->SetEnabled(false);

BButton* cancelButton = new BButton(B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED));
BButton* cancelButton = new BButton(B_TRANSLATE("Cancel"), new BMessage(MSG_INPUT_CANCEL));

float padding = be_control_look->DefaultItemSpacing();
if (fValues == 1) {
Expand Down Expand Up @@ -142,23 +142,43 @@ STLInputWindow::MessageReceived(BMessage* message)
switch (message->what) {
case MSG_INPUT_VALUE_UPDATED:
{
BMessage *msg = new BMessage(MSG_INPUT_VALUE_UPDATED);
msg->AddInt32("action",fMessageId);
msg->AddFloat("value0", atof(fValueControl->Text()));
if (fValues == 3) {
msg->AddFloat("value1", atof(fValueControl2->Text()));
msg->AddFloat("value2", atof(fValueControl3->Text()));
}
fTargetMessenger.SendMessage(msg);

/* Is this really working? */
bool enabled = fValueControl->Text() != NULL && fValueControl->Text()[0] != '\0';
if (fOkButton->IsEnabled() != enabled)
fOkButton->SetEnabled(enabled);
break;
}

case MSG_INPUT_OK:
{
BMessage *msg = new BMessage(fMessageId);
msg->AddString("value", fValueControl->Text());

msg->AddFloat("value0", atof(fValueControl->Text()));
if (fValues == 3) {
msg->AddString("value2", fValueControl2->Text());
msg->AddString("value3", fValueControl3->Text());
msg->AddFloat("value1", atof(fValueControl2->Text()));
msg->AddFloat("value2", atof(fValueControl3->Text()));
}
fTargetMessenger.SendMessage(msg);
PostMessage(B_QUIT_REQUESTED);
break;
}

case MSG_INPUT_CANCEL:
{
fTargetMessenger.SendMessage(MSG_INPUT_CANCEL);
PostMessage(B_QUIT_REQUESTED);
break;
}

default:
BWindow::MessageReceived(message);
break;
Expand Down
77 changes: 53 additions & 24 deletions STLView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "STLView.h"
#include "STLWindow.h"

#include <cstring>
#include <iostream>

using namespace std;

#undef B_TRANSLATION_CONTEXT
Expand All @@ -32,6 +34,7 @@ STLView::STLView(BRect frame, uint32 type)
showAxes(false),
showBox(false),
showOXY(false),
fShowPreview(false),
viewOrtho(false)
{
appIcon = STLoverApplication::GetIcon(NULL, 164);
Expand Down Expand Up @@ -176,11 +179,10 @@ STLView::Reset(bool scale, bool rotate, bool pan)
}

void
STLView::SetSTL(stl_file *_stl, stl_file *_stlView)
STLView::SetSTL(stl_file *stl)
{
LockGL();
stlObject = _stl;
stlObjectView = _stlView;
stlObject = stl;
SetupProjection();
Reset();
UnlockGL();
Expand All @@ -189,8 +191,8 @@ STLView::SetSTL(stl_file *_stl, stl_file *_stlView)
void
STLView::DrawBox(void)
{
stl_vertex min = stlObjectView->stats.min;
stl_vertex size = stlObjectView->stats.size;
stl_vertex min = stlObject->stats.min;
stl_vertex size = stlObject->stats.size;

glLineWidth(1);
glColor4f (0.9, 0.25, 0.6, 1);
Expand Down Expand Up @@ -224,14 +226,17 @@ STLView::DrawBox(void)
void
STLView::DrawOXY(float margin)
{
float xShift = stlObjectView->stats.min.x - stlObject->stats.min.x;
float yShift = stlObjectView->stats.min.y - stlObject->stats.min.y;
float zShift = stlObjectView->stats.min.z - stlObject->stats.min.z;

float xMin = lroundf((stlObjectView->stats.min.x + xShift) / 10.0) * 10.0 - margin;
float xMax = lroundf((stlObjectView->stats.max.x + xShift) / 10.0) * 10.0 + margin;
float yMin = lroundf((stlObjectView->stats.min.y + yShift) / 10.0) * 10.0 - margin;
float yMax = lroundf((stlObjectView->stats.max.y + yShift) / 10.0) * 10.0 + margin;
/*
TODO: check this
*/
float xShift = stlObject->stats.min.x - stlObject->stats.min.x;
float yShift = stlObject->stats.min.y - stlObject->stats.min.y;
float zShift = stlObject->stats.min.z - stlObject->stats.min.z;

float xMin = lroundf((stlObject->stats.min.x + xShift) / 10.0) * 10.0 - margin;
float xMax = lroundf((stlObject->stats.max.x + xShift) / 10.0) * 10.0 + margin;
float yMin = lroundf((stlObject->stats.min.y + yShift) / 10.0) * 10.0 - margin;
float yMax = lroundf((stlObject->stats.max.y + yShift) / 10.0) * 10.0 + margin;

glLineWidth(1);
glBegin(GL_LINES);
Expand All @@ -257,9 +262,9 @@ STLView::DrawOXY(float margin)
static void
Billboard()
{
float matrix[16];
float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX,matrix);

for (int i=0;i<3;i++) {
for (int j=0;j<3;j++) {
if (i==j) {
Expand All @@ -270,7 +275,7 @@ float matrix[16];
}
}
}

glLoadMatrixf(matrix);
}

Expand All @@ -279,7 +284,7 @@ STLView::DrawAxis(void)
{
double alpha = std::abs(cos(xRotate*M_PI/180.0));
double beta = std::abs(cos(yRotate*M_PI/180.0));

glLineWidth(1);

// Y axis
Expand Down Expand Up @@ -362,6 +367,20 @@ STLView::DrawAxis(void)
}
}

void
STLView::DrawSTL(rgb_color color)
{
glBegin(GL_TRIANGLES);
glColor3ub(color.red,color.green,color.blue);
for(size_t i = 0 ; i < stlObject->stats.number_of_facets ; i++) {
glNormal3f(stlObject->facet_start[i].normal.x, stlObject->facet_start[i].normal.y, stlObject->facet_start[i].normal.z);
glVertex3f(stlObject->facet_start[i].vertex[0].x, stlObject->facet_start[i].vertex[0].y, stlObject->facet_start[i].vertex[0].z);
glVertex3f(stlObject->facet_start[i].vertex[1].x, stlObject->facet_start[i].vertex[1].y, stlObject->facet_start[i].vertex[1].z);
glVertex3f(stlObject->facet_start[i].vertex[2].x, stlObject->facet_start[i].vertex[2].y, stlObject->facet_start[i].vertex[2].z);
}
glEnd();
}

void
STLView::Render(void)
{
Expand Down Expand Up @@ -396,15 +415,17 @@ STLView::Render(void)
glPolygonMode(GL_FRONT_AND_BACK, viewMode == MSG_VIEWMODE_WIREFRAME ? GL_LINE : GL_FILL);

glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);

glBegin(GL_TRIANGLES);
for(size_t i = 0 ; i < stlObjectView->stats.number_of_facets ; i++) {
glNormal3f(stlObjectView->facet_start[i].normal.x, stlObjectView->facet_start[i].normal.y, stlObjectView->facet_start[i].normal.z);
glVertex3f(stlObjectView->facet_start[i].vertex[0].x, stlObjectView->facet_start[i].vertex[0].y, stlObjectView->facet_start[i].vertex[0].z);
glVertex3f(stlObjectView->facet_start[i].vertex[1].x, stlObjectView->facet_start[i].vertex[1].y, stlObjectView->facet_start[i].vertex[1].z);
glVertex3f(stlObjectView->facet_start[i].vertex[2].x, stlObjectView->facet_start[i].vertex[2].y, stlObjectView->facet_start[i].vertex[2].z);
if (fShowPreview) {
glPushMatrix();
glMultMatrixf(fPreviewMatrix);
DrawSTL({128,101,0});
glPopMatrix();
}
else {
DrawSTL();
}
glEnd();

glDisable(GL_LIGHTING);

Expand Down Expand Up @@ -451,3 +472,11 @@ STLView::Render(void)
UnlockGL();
}
}

void
STLView::ShowPreview(float *matrix)
{
std::memcpy(fPreviewMatrix,matrix,sizeof(float)*16);
fShowPreview=true;
RenderUpdate();
}
10 changes: 8 additions & 2 deletions STLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class STLView : public BGLView {
virtual void MouseUp(BPoint point);
virtual void MouseMoved(BPoint p, uint32 transit,const BMessage *message);

void SetSTL(stl_file *stl, stl_file *stlView);
void SetSTL(stl_file *stl);
void Reset(bool scale = true, bool rotate = true, bool pan = true);
void ShowAxes(bool show) { showAxes = show; }
void ShowBoundingBox(bool show) { showBox = show; }
Expand All @@ -57,12 +57,17 @@ class STLView : public BGLView {
void SetYRotate(float value) { yRotate = value; needUpdate = true;}
void SetScaleFactor(float value) { scaleFactor = value; needUpdate = true;}

void ShowPreview(float *matrix);
void HidePreview() { fShowPreview = false;}
private:
void DrawBox(void);
void DrawAxis(void);
void DrawOXY(float margin = 30.0);

void SetupProjection(void);

void DrawSTL() { DrawSTL({128,128,128});}
void DrawSTL(rgb_color color);

BRect boundRect;
BBitmap *appIcon;
Expand All @@ -74,7 +79,6 @@ class STLView : public BGLView {
STLWindow *stlWindow;

stl_file* stlObject;
stl_file* stlObjectView;

float xRotate;
float yRotate;
Expand All @@ -87,6 +91,8 @@ class STLView : public BGLView {
bool showBox;
bool showAxes;
bool showOXY;
float fPreviewMatrix[16];
bool fShowPreview;
bool viewOrtho;
};

Expand Down
Loading

0 comments on commit 931e301

Please sign in to comment.