Skip to content

Commit

Permalink
add 'no shading' and 'hidden line' styles
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 3, 2017
1 parent 81884f7 commit adca327
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
38 changes: 38 additions & 0 deletions src/Gui/CommandView.cpp
Expand Up @@ -607,6 +607,18 @@ Gui::Action * StdCmdDrawStyle::createAction(void)
a4->setIcon(BitmapFactory().iconFromTheme("DrawStylePoints"));
a4->setObjectName(QString::fromLatin1("Std_DrawStylePoints"));
a4->setShortcut(QKeySequence(QString::fromUtf8("V,5")));
QAction* a5 = pcAction->addAction(QString());
a5->setCheckable(true);
a5->setIcon(BitmapFactory().iconFromTheme("DrawStyleWireFrame"));
a5->setObjectName(QString::fromLatin1("Std_DrawStyleHiddenLine"));
a5->setShortcut(QKeySequence(QString::fromUtf8("V,6")));
QAction* a6 = pcAction->addAction(QString());
a6->setCheckable(true);
a6->setIcon(BitmapFactory().iconFromTheme("DrawStyleWireFrame"));
a6->setObjectName(QString::fromLatin1("Std_DrawStyleNoShading"));
a6->setShortcut(QKeySequence(QString::fromUtf8("V,7")));


pcAction->setIcon(a0->icon());

_pcAction = pcAction;
Expand Down Expand Up @@ -647,6 +659,16 @@ void StdCmdDrawStyle::languageChange()
"Std_DrawStyle", "Points"));
a[4]->setToolTip(QCoreApplication::translate(
"Std_DrawStyle", "Points mode"));

a[5]->setText(QCoreApplication::translate(
"Std_DrawStyle", "Hidden line"));
a[5]->setToolTip(QCoreApplication::translate(
"Std_DrawStyle", "Hidden line mode"));

a[6]->setText(QCoreApplication::translate(
"Std_DrawStyle", "No shading"));
a[6]->setToolTip(QCoreApplication::translate(
"Std_DrawStyle", "No shading mode"));
}

void StdCmdDrawStyle::updateIcon(const MDIView *view)
Expand Down Expand Up @@ -682,6 +704,16 @@ void StdCmdDrawStyle::updateIcon(const MDIView *view)
actionGroup->setCheckedAction(4);
return;
}
if (mode == "Hidden Line")
{
actionGroup->setCheckedAction(5);
return;
}
if (mode == "No shading")
{
actionGroup->setCheckedAction(6);
return;
}
actionGroup->setCheckedAction(0);
}

Expand Down Expand Up @@ -714,6 +746,12 @@ void StdCmdDrawStyle::activated(int iMsg)
case 4:
(oneChangedSignal) ? viewer->updateOverrideMode("Point") : viewer->setOverrideMode("Point");
break;
case 5:
(oneChangedSignal) ? viewer->updateOverrideMode("Hidden Line") : viewer->setOverrideMode("Hidden Line");
break;
case 6:
(oneChangedSignal) ? viewer->updateOverrideMode("No Shading") : viewer->setOverrideMode("No Shading");
break;
default:
(oneChangedSignal) ? viewer->updateOverrideMode("As Is") : viewer->setOverrideMode("As Is");
break;
Expand Down
52 changes: 47 additions & 5 deletions src/Gui/View3DInventorViewer.cpp
Expand Up @@ -125,6 +125,8 @@

#include <Inventor/draggers/SoCenterballDragger.h>
#include <Inventor/annex/Profiler/SoProfiler.h>
#include <Inventor/elements/SoOverrideElement.h>
#include <Inventor/elements/SoLightModelElement.h>
#include <QGesture>

#include "SoTouchEvents.h"
Expand Down Expand Up @@ -351,6 +353,7 @@ View3DInventorViewer::View3DInventorViewer(const QGLFormat& format, QWidget* par

void View3DInventorViewer::init()
{
shading = true;
fpsEnabled = false;
vboEnabled = false;

Expand Down Expand Up @@ -707,8 +710,26 @@ void View3DInventorViewer::setOverrideMode(const std::string& mode)
overrideMode = mode;

auto views = getDocument()->getViewProvidersOfType(Gui::ViewProvider::getClassTypeId());
for (auto view : views)
view->setOverrideMode(mode);
if (mode == "No Shading") {
this->shading = false;
std::string flatLines = "Flat Lines";
for (auto view : views)
view->setOverrideMode(flatLines);
this->getSoRenderManager()->setRenderMode(SoRenderManager::AS_IS);
}
else if (mode == "Hidden Line") {
this->shading = true;
std::string shaded = "Shaded";
for (auto view : views)
view->setOverrideMode(shaded);
this->getSoRenderManager()->setRenderMode(SoRenderManager::HIDDEN_LINE);
}
else {
this->shading = true;
for (auto view : views)
view->setOverrideMode(mode);
this->getSoRenderManager()->setRenderMode(SoRenderManager::AS_IS);
}
}

/// update override mode. doesn't affect providers
Expand Down Expand Up @@ -965,6 +986,12 @@ void View3DInventorViewer::savePicture(int w, int h, const QColor& bg, QImage& i
root->addChild(cb);
}

if (!this->shading) {
SoLightModel* lm = new SoLightModel;
lm->model = SoLightModel::BASE_COLOR;
root->addChild(lm);
}

root->addChild(getHeadlight());
root->addChild(camera);
SoCallback* gl = new SoCallback;
Expand Down Expand Up @@ -1327,6 +1354,10 @@ void View3DInventorViewer::renderToFramebuffer(QGLFramebufferObject* fbo)
uint32_t id = this->getSoRenderManager()->getGLRenderAction()->getCacheContext();
gl.setCacheContext(id);
gl.setTransparencyType(SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND);
if (!this->shading) {
SoLightModelElement::set(gl.getState(), selectionRoot, SoLightModelElement::BASE_COLOR);
SoOverrideElement::setLightModelOverride(gl.getState(), selectionRoot, true);
}
gl.apply(this->backgroundroot);
gl.apply(this->getSoRenderManager()->getSceneGraph());
gl.apply(this->foregroundroot);
Expand Down Expand Up @@ -1451,13 +1482,20 @@ void View3DInventorViewer::renderScene(void)

// Render our scenegraph with the image.
SoGLRenderAction* glra = this->getSoRenderManager()->getGLRenderAction();
SoGLWidgetElement::set(glra->getState(), qobject_cast<QGLWidget*>(this->getGLWidget()));
SoGLRenderActionElement::set(glra->getState(), glra);
SoGLVBOActivatedElement::set(glra->getState(), this->vboEnabled);
SoState* state = glra->getState();
SoGLWidgetElement::set(state, qobject_cast<QGLWidget*>(this->getGLWidget()));
SoGLRenderActionElement::set(state, glra);
SoGLVBOActivatedElement::set(state, this->vboEnabled);
glra->apply(this->backgroundroot);

navigation->updateAnimation();

if (!this->shading) {
state->push();
SoLightModelElement::set(state, selectionRoot, SoLightModelElement::BASE_COLOR);
SoOverrideElement::setLightModelOverride(state, selectionRoot, true);
}

try {
// Render normal scenegraph.
inherited::actualRedraw();
Expand All @@ -1472,6 +1510,10 @@ void View3DInventorViewer::renderScene(void)
QObject::tr("Not enough memory available to display the data."));
}

if (!this->shading) {
state->pop();
}

#if defined (ENABLE_GL_DEPTH_RANGE)
// using 10% of the z-buffer for the foreground node
glDepthRange(0.0,0.1);
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/View3DInventorViewer.h
Expand Up @@ -338,6 +338,7 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi
void setAxisCross(bool b);
bool hasAxisCross(void);


void setEnabledFPSCounter(bool b);
void setEnabledVBO(bool b);
bool isEnabledVBO() const;
Expand Down Expand Up @@ -410,6 +411,7 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi
RenderType renderType;
QGLFramebufferObject* framebuffer;
QImage glImage;
SbBool shading;
SoSwitch *dimensionRoot;

// small axis cross in the corner
Expand Down

0 comments on commit adca327

Please sign in to comment.