+ fix broken brush selection
This commit is contained in:
parent
6b6070281e
commit
d8f63bcfd1
|
@ -293,11 +293,14 @@ void Rubberband::paintGL()
|
|||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
Polyline::Polyline(View3DInventorViewer* v) : viewer(v)
|
||||
{
|
||||
x_new = y_new = 0;
|
||||
working = false;
|
||||
closed = true;
|
||||
stippled = false;
|
||||
line = 2.0;
|
||||
}
|
||||
|
||||
|
@ -306,6 +309,7 @@ Polyline::Polyline()
|
|||
x_new = y_new = 0;
|
||||
working = false;
|
||||
closed = true;
|
||||
stippled = false;
|
||||
line = 2.0;
|
||||
}
|
||||
|
||||
|
@ -318,7 +322,7 @@ void Polyline::setWorking(bool on)
|
|||
working = on;
|
||||
}
|
||||
|
||||
bool Polyline::isWorking()
|
||||
bool Polyline::isWorking() const
|
||||
{
|
||||
return working;
|
||||
}
|
||||
|
@ -347,6 +351,11 @@ void Polyline::setClosed(bool c)
|
|||
closed = c;
|
||||
}
|
||||
|
||||
void Polyline::setCloseStippled(bool c)
|
||||
{
|
||||
stippled = c;
|
||||
}
|
||||
|
||||
void Polyline::setLineWidth(float l)
|
||||
{
|
||||
line = l;
|
||||
|
@ -383,17 +392,38 @@ void Polyline::paintGL()
|
|||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glLineWidth(line);
|
||||
glColor4f(rgb_r, rgb_g, rgb_b, rgb_a);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
|
||||
QPoint start = _cNodeVector.front();
|
||||
if (closed && !stippled) {
|
||||
glBegin(GL_LINE_LOOP);
|
||||
|
||||
for (std::vector<QPoint>::iterator it = _cNodeVector.begin(); it != _cNodeVector.end(); ++it) {
|
||||
glVertex2i(it->x(), it->y());
|
||||
for (std::vector<QPoint>::iterator it = _cNodeVector.begin(); it != _cNodeVector.end(); ++it) {
|
||||
glVertex2i(it->x(), it->y());
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
else {
|
||||
glBegin(GL_LINES);
|
||||
|
||||
QPoint start = _cNodeVector.front();
|
||||
for (std::vector<QPoint>::iterator it = _cNodeVector.begin(); it != _cNodeVector.end(); ++it) {
|
||||
glVertex2i(start.x(), start.y());
|
||||
start = *it;
|
||||
glVertex2i(it->x(), it->y());
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
if (closed && stippled) {
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glLineStipple(2, 0x3F3F);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(_cNodeVector.back().x(), _cNodeVector.back().y());
|
||||
glVertex2i(_cNodeVector.front().x(), _cNodeVector.front().y());
|
||||
glEnd();
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_cNodeVector.empty())
|
||||
glVertex2i(x_new, y_new);
|
||||
|
||||
glEnd();
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ class Polyline : public Gui::GLGraphicsItem
|
|||
std::vector<QPoint> _cNodeVector;
|
||||
int x_new, y_new;
|
||||
float rgb_r, rgb_g, rgb_b, rgb_a, line;
|
||||
bool working, closed;
|
||||
bool working, closed, stippled;
|
||||
GLPainter p;
|
||||
|
||||
public:
|
||||
|
@ -127,12 +127,13 @@ public:
|
|||
Polyline();
|
||||
~Polyline();
|
||||
void setWorking(bool on);
|
||||
bool isWorking();
|
||||
bool isWorking() const;
|
||||
void setViewer(View3DInventorViewer* v);
|
||||
void setCoords(int x, int y);
|
||||
void setColor(int r, int g, int b, int a=0);
|
||||
void setLineWidth(float l);
|
||||
void setClosed(bool c);
|
||||
void setCloseStippled(bool c);
|
||||
void addNode(const QPoint& p);
|
||||
void clear();
|
||||
void paintGL();
|
||||
|
|
|
@ -251,6 +251,16 @@ PolyPickerSelection::PolyPickerSelection()
|
|||
{
|
||||
}
|
||||
|
||||
void PolyPickerSelection::setColor(float r, float g, float b, float a)
|
||||
{
|
||||
polyline.setColor(r,g,b,a);
|
||||
}
|
||||
|
||||
void PolyPickerSelection::setLineWidth(float l)
|
||||
{
|
||||
polyline.setLineWidth(l);
|
||||
}
|
||||
|
||||
void PolyPickerSelection::initialize()
|
||||
{
|
||||
QPixmap p(cursor_cut_scissors);
|
||||
|
@ -258,8 +268,7 @@ void PolyPickerSelection::initialize()
|
|||
_pcView3D->getWidget()->setCursor(cursor);
|
||||
|
||||
polyline.setViewer(_pcView3D);
|
||||
polyline.setColor(0.0,0.0,1.0,1.0);
|
||||
|
||||
|
||||
_pcView3D->addGraphicsItem(&polyline);
|
||||
_pcView3D->setRenderType(View3DInventorViewer::Image);
|
||||
_pcView3D->redraw();
|
||||
|
@ -456,25 +465,15 @@ BrushSelection::BrushSelection()
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
BrushSelection::~BrushSelection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BrushSelection::setColor(float r, float g, float b, float a)
|
||||
{
|
||||
polyline.setColor(r,g,b,a);
|
||||
}
|
||||
|
||||
void BrushSelection::setLineWidth(float l)
|
||||
{
|
||||
polyline.setLineWidth(l);
|
||||
}
|
||||
|
||||
void BrushSelection::setClosed(bool on)
|
||||
{
|
||||
//TODO: closed = false is not supported yet
|
||||
polyline.setClosed(on);
|
||||
polyline.setCloseStippled(true);
|
||||
}
|
||||
|
||||
int BrushSelection::popupMenu()
|
||||
|
@ -484,11 +483,10 @@ int BrushSelection::popupMenu()
|
|||
menu.addAction(QObject::tr("Clear"));
|
||||
QAction* ca = menu.addAction(QObject::tr("Cancel"));
|
||||
|
||||
if(getPositions().size() < 3)
|
||||
if (getPositions().size() < 3)
|
||||
fi->setEnabled(false);
|
||||
|
||||
QAction* id = menu.exec(QCursor::pos());
|
||||
|
||||
if (id == fi)
|
||||
return Finish;
|
||||
else if (id == ca)
|
||||
|
@ -497,6 +495,80 @@ int BrushSelection::popupMenu()
|
|||
return Restart;
|
||||
}
|
||||
|
||||
int BrushSelection::mouseButtonEvent(const SoMouseButtonEvent* const e, const QPoint& pos)
|
||||
{
|
||||
const int button = e->getButton();
|
||||
const SbBool press = e->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
|
||||
|
||||
if (press) {
|
||||
switch(button)
|
||||
{
|
||||
case SoMouseButtonEvent::BUTTON1:
|
||||
{
|
||||
if (!polyline.isWorking()) {
|
||||
polyline.setWorking(true);
|
||||
polyline.clear();
|
||||
};
|
||||
polyline.addNode(pos);
|
||||
polyline.setCoords(pos.x(), pos.y());
|
||||
m_iXnew = pos.x(); m_iYnew = pos.y();
|
||||
m_iXold = pos.x(); m_iYold = pos.y();
|
||||
}
|
||||
break;
|
||||
|
||||
case SoMouseButtonEvent::BUTTON2:
|
||||
{
|
||||
polyline.addNode(pos);
|
||||
m_iXnew = pos.x(); m_iYnew = pos.y();
|
||||
m_iXold = pos.x(); m_iYold = pos.y();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
} break;
|
||||
}
|
||||
}
|
||||
// release
|
||||
else {
|
||||
switch(button)
|
||||
{
|
||||
case SoMouseButtonEvent::BUTTON1:
|
||||
if (polyline.isWorking()) {
|
||||
releaseMouseModel();
|
||||
return Finish;
|
||||
}
|
||||
case SoMouseButtonEvent::BUTTON2:
|
||||
{
|
||||
QCursor cur = _pcView3D->getWidget()->cursor();
|
||||
_pcView3D->getWidget()->setCursor(m_cPrevCursor);
|
||||
|
||||
// The pop-up menu should be shown when releasing mouse button because
|
||||
// otherwise the navigation style doesn't get the UP event and gets into
|
||||
// an inconsistent state.
|
||||
int id = popupMenu();
|
||||
|
||||
if (id == Finish || id == Cancel) {
|
||||
releaseMouseModel();
|
||||
}
|
||||
else if (id == Restart) {
|
||||
_pcView3D->getWidget()->setCursor(cur);
|
||||
}
|
||||
|
||||
polyline.setWorking(false);
|
||||
return id;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
return Continue;
|
||||
}
|
||||
|
||||
int BrushSelection::locationEvent(const SoLocation2Event* const e, const QPoint& pos)
|
||||
{
|
||||
// do all the drawing stuff for us
|
||||
|
@ -541,30 +613,24 @@ int BrushSelection::locationEvent(const SoLocation2Event* const e, const QPoint&
|
|||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
RectangleSelection::RectangleSelection() : RubberbandSelection()
|
||||
{
|
||||
rubberband.setColor(0.0,0.0,1.0,1.0);
|
||||
}
|
||||
|
||||
RectangleSelection::~RectangleSelection()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
RubberbandSelection::RubberbandSelection()
|
||||
{
|
||||
rubberband.setColor(1.0, 1.0, 0.0, 0.5);
|
||||
}
|
||||
|
||||
RubberbandSelection::~RubberbandSelection()
|
||||
{
|
||||
}
|
||||
|
||||
void RubberbandSelection::setColor(float r, float g, float b, float a)
|
||||
{
|
||||
rubberband.setColor(r,g,b,a);
|
||||
}
|
||||
|
||||
void RubberbandSelection::initialize()
|
||||
{
|
||||
rubberband.setViewer(_pcView3D);
|
||||
rubberband.setWorking(false);
|
||||
rubberband.setColor(1.0, 1.0, 0.0, 0.5);
|
||||
_pcView3D->addGraphicsItem(&rubberband);
|
||||
if (QGLFramebufferObject::hasOpenGLFramebufferObjects()) {
|
||||
_pcView3D->setRenderType(View3DInventorViewer::Image);
|
||||
|
@ -645,6 +711,17 @@ int RubberbandSelection::keyboardEvent(const SoKeyboardEvent* const e)
|
|||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
RectangleSelection::RectangleSelection() : RubberbandSelection()
|
||||
{
|
||||
rubberband.setColor(0.0,0.0,1.0,1.0);
|
||||
}
|
||||
|
||||
RectangleSelection::~RectangleSelection()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
BoxZoomSelection::BoxZoomSelection()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ class GuiExport BaseMouseSelection : public AbstractMouseSelection
|
|||
{
|
||||
public:
|
||||
BaseMouseSelection();
|
||||
virtual ~BaseMouseSelection() {};
|
||||
virtual ~BaseMouseSelection(){}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
@ -129,6 +129,9 @@ public:
|
|||
PolyPickerSelection();
|
||||
virtual ~PolyPickerSelection();
|
||||
|
||||
void setLineWidth(float l);
|
||||
void setColor(float r, float g, float b, float a = 1.0);
|
||||
|
||||
virtual void initialize();
|
||||
virtual void terminate();
|
||||
|
||||
|
@ -173,12 +176,11 @@ public:
|
|||
BrushSelection();
|
||||
virtual ~BrushSelection();
|
||||
|
||||
void setLineWidth(float l);
|
||||
void setClosed(bool c);
|
||||
void setColor(float r, float g, float b, float a = 1.0);
|
||||
|
||||
protected:
|
||||
virtual int popupMenu();
|
||||
virtual int mouseButtonEvent(const SoMouseButtonEvent* const e, const QPoint& pos);
|
||||
virtual int locationEvent(const SoLocation2Event* const e, const QPoint& pos);
|
||||
};
|
||||
|
||||
|
@ -195,9 +197,9 @@ public:
|
|||
RubberbandSelection();
|
||||
virtual ~RubberbandSelection();
|
||||
|
||||
/// do nothing
|
||||
void setColor(float r, float g, float b, float a = 1.0);
|
||||
|
||||
virtual void initialize();
|
||||
/// do nothing
|
||||
virtual void terminate();
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue
Block a user