+ Simplify usage of templates
This commit is contained in:
parent
01d5193296
commit
46a0ec259f
|
@ -109,5 +109,7 @@ short LuxProject::mustExecute() const
|
|||
{
|
||||
if (Camera.isTouched())
|
||||
return 1;
|
||||
if (Template.isTouched())
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,10 @@ public:
|
|||
/// recalculate the Feature
|
||||
App::DocumentObjectExecReturn *execute(void);
|
||||
short mustExecute() const;
|
||||
//@}
|
||||
const char* getViewProviderName(void) const {
|
||||
return "RaytracingGui::ViewProviderLux";
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -102,5 +102,7 @@ short RayProject::mustExecute() const
|
|||
{
|
||||
if (Camera.isTouched())
|
||||
return 1;
|
||||
if (Template.isTouched())
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,10 @@ public:
|
|||
/// recalculate the Feature
|
||||
App::DocumentObjectExecReturn *execute(void);
|
||||
short mustExecute() const;
|
||||
//@}
|
||||
const char* getViewProviderName(void) const {
|
||||
return "RaytracingGui::ViewProviderPovray";
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <Gui/Language/Translator.h>
|
||||
|
||||
#include "DlgSettingsRayImp.h"
|
||||
#include "ViewProvider.h"
|
||||
#include "Workbench.h"
|
||||
#include "qrc_Raytracing.cpp"
|
||||
|
||||
|
@ -69,7 +70,9 @@ void AppRaytracingGuiExport initRaytracingGui()
|
|||
|
||||
// instantiating the commands
|
||||
CreateRaytracingCommands();
|
||||
RaytracingGui::Workbench::init();
|
||||
RaytracingGui::ViewProviderLux ::init();
|
||||
RaytracingGui::ViewProviderPovray ::init();
|
||||
RaytracingGui::Workbench ::init();
|
||||
|
||||
// register preferences pages
|
||||
new Gui::PrefPageProducer<DlgSettingsRayImp> ("Raytracing");
|
||||
|
|
|
@ -68,6 +68,8 @@ SET(RaytracingGui_SRCS
|
|||
PovrayHighlighter.h
|
||||
PreCompiled.cpp
|
||||
PreCompiled.h
|
||||
ViewProvider.cpp
|
||||
ViewProvider.h
|
||||
Workbench.cpp
|
||||
Workbench.h
|
||||
)
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
# include <vector>
|
||||
# include <Inventor/nodes/SoPerspectiveCamera.h>
|
||||
# include <QApplication>
|
||||
# include <QFile>
|
||||
# include <QFileInfo>
|
||||
# include <QMessageBox>
|
||||
#endif
|
||||
|
||||
|
@ -43,7 +45,9 @@
|
|||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/Material.h>
|
||||
#include <Gui/Action.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/FileDialog.h>
|
||||
|
@ -293,7 +297,7 @@ bool CmdRaytracingWriteView::isActive(void)
|
|||
// Raytracing_NewPovrayProject
|
||||
//===========================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdRaytracingNewPovrayProject);
|
||||
DEF_STD_CMD_AC(CmdRaytracingNewPovrayProject);
|
||||
|
||||
CmdRaytracingNewPovrayProject::CmdRaytracingNewPovrayProject()
|
||||
: Command("Raytracing_NewPovrayProject")
|
||||
|
@ -327,12 +331,56 @@ void CmdRaytracingNewPovrayProject::activated(int iMsg)
|
|||
|
||||
std::string FeatName = getUniqueObjectName("PovProject");
|
||||
|
||||
openCommand("Raytracing create project");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Raytracing::RayProject','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = App.getResourceDir()+'Mod/Raytracing/Templates/ProjectStd.pov'",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",FeatName.c_str());
|
||||
commitCommand();
|
||||
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(getAction());
|
||||
QAction* a = pcAction->actions()[iMsg];
|
||||
QFileInfo tfi(a->property("Template").toString());
|
||||
if (tfi.isReadable()) {
|
||||
openCommand("Raytracing create project");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Raytracing::RayProject','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8());
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",FeatName.c_str());
|
||||
commitCommand();
|
||||
}
|
||||
else {
|
||||
QMessageBox::critical(Gui::getMainWindow(),
|
||||
qApp->translate("CmdRaytracingNewPovrayProject","No template"),
|
||||
qApp->translate("CmdRaytracingNewPovrayProject","No template available"));
|
||||
}
|
||||
}
|
||||
|
||||
Gui::Action * CmdRaytracingNewPovrayProject::createAction(void)
|
||||
{
|
||||
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
|
||||
pcAction->setDropDownMenu(true);
|
||||
applyCommandData(pcAction);
|
||||
|
||||
QAction* defaultAction = 0;
|
||||
int defaultId = 0;
|
||||
|
||||
std::string path = App::Application::getResourceDir();
|
||||
path += "Mod/Raytracing/Templates/";
|
||||
QDir dir(QString::fromUtf8(path.c_str()), QString::fromAscii("*.pov"));
|
||||
for (unsigned int i=0; i<dir.count(); i++ ) {
|
||||
QFileInfo fi(dir[i]);
|
||||
QAction* a = pcAction->addAction(fi.baseName());
|
||||
a->setIcon(Gui::BitmapFactory().pixmap("Raytrace_New"));
|
||||
|
||||
a->setProperty("Template", dir.absoluteFilePath(dir[i]));
|
||||
}
|
||||
|
||||
_pcAction = pcAction;
|
||||
languageChange();
|
||||
if (defaultAction) {
|
||||
pcAction->setIcon(defaultAction->icon());
|
||||
pcAction->setProperty("defaultAction", QVariant(defaultId));
|
||||
}
|
||||
else if (!pcAction->actions().isEmpty()) {
|
||||
pcAction->setIcon(pcAction->actions()[0]->icon());
|
||||
pcAction->setProperty("defaultAction", QVariant(0));
|
||||
}
|
||||
|
||||
return pcAction;
|
||||
}
|
||||
|
||||
bool CmdRaytracingNewPovrayProject::isActive(void)
|
||||
|
@ -606,7 +654,7 @@ bool CmdRaytracingRender::isActive(void)
|
|||
// Raytracing_NewLuxProject
|
||||
//===========================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdRaytracingNewLuxProject);
|
||||
DEF_STD_CMD_AC(CmdRaytracingNewLuxProject);
|
||||
|
||||
CmdRaytracingNewLuxProject::CmdRaytracingNewLuxProject()
|
||||
: Command("Raytracing_NewLuxProject")
|
||||
|
@ -640,12 +688,56 @@ void CmdRaytracingNewLuxProject::activated(int iMsg)
|
|||
|
||||
std::string FeatName = getUniqueObjectName("LuxProject");
|
||||
|
||||
openCommand("Raytracing create luxrender project");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Raytracing::LuxProject','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = App.getResourceDir()+'Mod/Raytracing/Templates/LuxClassic.lxs'",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",FeatName.c_str());
|
||||
commitCommand();
|
||||
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(getAction());
|
||||
QAction* a = pcAction->actions()[iMsg];
|
||||
QFileInfo tfi(a->property("Template").toString());
|
||||
if (tfi.isReadable()) {
|
||||
openCommand("Raytracing create luxrender project");
|
||||
doCommand(Doc,"import Raytracing,RaytracingGui");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Raytracing::LuxProject','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8());
|
||||
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",FeatName.c_str());
|
||||
commitCommand();
|
||||
}
|
||||
else {
|
||||
QMessageBox::critical(Gui::getMainWindow(),
|
||||
qApp->translate("CmdRaytracingNewLuxProject","No template"),
|
||||
qApp->translate("CmdRaytracingNewLuxProject","No template available"));
|
||||
}
|
||||
}
|
||||
|
||||
Gui::Action * CmdRaytracingNewLuxProject::createAction(void)
|
||||
{
|
||||
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
|
||||
pcAction->setDropDownMenu(true);
|
||||
applyCommandData(pcAction);
|
||||
|
||||
QAction* defaultAction = 0;
|
||||
int defaultId = 0;
|
||||
|
||||
std::string path = App::Application::getResourceDir();
|
||||
path += "Mod/Raytracing/Templates/";
|
||||
QDir dir(QString::fromUtf8(path.c_str()), QString::fromAscii("*.lxs"));
|
||||
for (unsigned int i=0; i<dir.count(); i++ ) {
|
||||
QFileInfo fi(dir[i]);
|
||||
QAction* a = pcAction->addAction(fi.baseName());
|
||||
a->setIcon(Gui::BitmapFactory().pixmap("Raytrace_Lux"));
|
||||
|
||||
a->setProperty("Template", dir.absoluteFilePath(dir[i]));
|
||||
}
|
||||
|
||||
_pcAction = pcAction;
|
||||
languageChange();
|
||||
if (defaultAction) {
|
||||
pcAction->setIcon(defaultAction->icon());
|
||||
pcAction->setProperty("defaultAction", QVariant(defaultId));
|
||||
}
|
||||
else if (!pcAction->actions().isEmpty()) {
|
||||
pcAction->setIcon(pcAction->actions()[0]->icon());
|
||||
pcAction->setProperty("defaultAction", QVariant(0));
|
||||
}
|
||||
|
||||
return pcAction;
|
||||
}
|
||||
|
||||
bool CmdRaytracingNewLuxProject::isActive(void)
|
||||
|
|
178
src/Mod/Raytracing/Gui/ViewProvider.cpp
Normal file
178
src/Mod/Raytracing/Gui/ViewProvider.cpp
Normal file
|
@ -0,0 +1,178 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2013 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QAction>
|
||||
# include <QDir>
|
||||
# include <QFileInfo>
|
||||
# include <QMenu>
|
||||
# include <QInputDialog>
|
||||
#endif
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include <Mod/Raytracing/App/LuxProject.h>
|
||||
#include <Mod/Raytracing/App/RayProject.h>
|
||||
#include <App/Application.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
|
||||
|
||||
using namespace RaytracingGui;
|
||||
|
||||
|
||||
/* TRANSLATOR RaytracingGui::ViewProviderLux */
|
||||
|
||||
PROPERTY_SOURCE(RaytracingGui::ViewProviderLux, Gui::ViewProviderDocumentObjectGroup)
|
||||
|
||||
ViewProviderLux::ViewProviderLux()
|
||||
{
|
||||
}
|
||||
|
||||
ViewProviderLux::~ViewProviderLux()
|
||||
{
|
||||
}
|
||||
|
||||
bool ViewProviderLux::doubleClicked(void)
|
||||
{
|
||||
Gui::Application::Instance->activeDocument()->setEdit(this, (int)ViewProvider::Default);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderLux::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
QAction* act;
|
||||
act = menu->addAction(QObject::tr("Edit project"), receiver, member);
|
||||
act->setData(QVariant((int)ViewProvider::Default));
|
||||
ViewProviderDocumentObjectGroup::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderLux::setEdit(int ModNum)
|
||||
{
|
||||
if (ModNum == ViewProvider::Default ) {
|
||||
std::string path = App::Application::getResourceDir();
|
||||
path += "Mod/Raytracing/Templates/";
|
||||
QString dataDir = QString::fromUtf8(path.c_str());
|
||||
QDir dir(dataDir, QString::fromAscii("*.lxs"));
|
||||
QStringList items;
|
||||
int current = 0;
|
||||
QFileInfo cfi(QString::fromUtf8(static_cast<Raytracing::LuxProject*>(getObject())->Template.getValue()));
|
||||
for (unsigned int i=0; i<dir.count(); i++ ) {
|
||||
QFileInfo fi(dir[i]);
|
||||
items << fi.baseName();
|
||||
if (fi.baseName() == cfi.baseName()) {
|
||||
current = i;
|
||||
}
|
||||
}
|
||||
|
||||
bool ok;
|
||||
QString file = QInputDialog::getItem(Gui::getMainWindow(), tr("Template"), tr("Select a template"), items, current, false, &ok);
|
||||
if (ok) {
|
||||
QString fn = QString::fromAscii("%1%2.lxs").arg(dataDir).arg(file);
|
||||
static_cast<Raytracing::LuxProject*>(getObject())->Template.setValue((const char*)fn.toUtf8());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return ViewProviderDocumentObjectGroup::setEdit(ModNum);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderLux::unsetEdit(int ModNum)
|
||||
{
|
||||
if (ModNum == ViewProvider::Default) {
|
||||
}
|
||||
else {
|
||||
ViewProviderDocumentObjectGroup::unsetEdit(ModNum);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/* TRANSLATOR RaytracingGui::ViewProviderPovray */
|
||||
|
||||
PROPERTY_SOURCE(RaytracingGui::ViewProviderPovray, Gui::ViewProviderDocumentObjectGroup)
|
||||
|
||||
ViewProviderPovray::ViewProviderPovray()
|
||||
{
|
||||
}
|
||||
|
||||
ViewProviderPovray::~ViewProviderPovray()
|
||||
{
|
||||
}
|
||||
|
||||
bool ViewProviderPovray::doubleClicked(void)
|
||||
{
|
||||
Gui::Application::Instance->activeDocument()->setEdit(this, (int)ViewProvider::Default);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderPovray::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
QAction* act;
|
||||
act = menu->addAction(QObject::tr("Edit project"), receiver, member);
|
||||
act->setData(QVariant((int)ViewProvider::Default));
|
||||
ViewProviderDocumentObjectGroup::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderPovray::setEdit(int ModNum)
|
||||
{
|
||||
if (ModNum == ViewProvider::Default ) {
|
||||
std::string path = App::Application::getResourceDir();
|
||||
path += "Mod/Raytracing/Templates/";
|
||||
QString dataDir = QString::fromUtf8(path.c_str());
|
||||
QDir dir(dataDir, QString::fromAscii("*.pov"));
|
||||
QStringList items;
|
||||
int current = 0;
|
||||
QFileInfo cfi(QString::fromUtf8(static_cast<Raytracing::RayProject*>(getObject())->Template.getValue()));
|
||||
for (unsigned int i=0; i<dir.count(); i++ ) {
|
||||
QFileInfo fi(dir[i]);
|
||||
items << fi.baseName();
|
||||
if (fi.baseName() == cfi.baseName()) {
|
||||
current = i;
|
||||
}
|
||||
}
|
||||
|
||||
bool ok;
|
||||
QString file = QInputDialog::getItem(Gui::getMainWindow(), tr("Template"), tr("Select a template"), items, current, false, &ok);
|
||||
if (ok) {
|
||||
QString fn = QString::fromAscii("%1%2.pov").arg(dataDir).arg(file);
|
||||
static_cast<Raytracing::RayProject*>(getObject())->Template.setValue((const char*)fn.toUtf8());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return ViewProviderDocumentObjectGroup::setEdit(ModNum);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderPovray::unsetEdit(int ModNum)
|
||||
{
|
||||
if (ModNum == ViewProvider::Default) {
|
||||
}
|
||||
else {
|
||||
ViewProviderDocumentObjectGroup::unsetEdit(ModNum);
|
||||
}
|
||||
}
|
70
src/Mod/Raytracing/Gui/ViewProvider.h
Normal file
70
src/Mod/Raytracing/Gui/ViewProvider.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2013 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef RAYTRACINGGUI_VIEWPROVIDER_H
|
||||
#define RAYTRACINGGUI_VIEWPROVIDER_H
|
||||
|
||||
|
||||
#include <Gui/ViewProviderDocumentObjectGroup.h>
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace RaytracingGui {
|
||||
|
||||
class ViewProviderLux : public Gui::ViewProviderDocumentObjectGroup
|
||||
{
|
||||
PROPERTY_HEADER(RaytracingGui::ViewProviderLux);
|
||||
Q_DECLARE_TR_FUNCTIONS(RaytracingGui::ViewProviderLux)
|
||||
|
||||
public:
|
||||
ViewProviderLux();
|
||||
virtual ~ViewProviderLux();
|
||||
|
||||
bool doubleClicked(void);
|
||||
void setupContextMenu(QMenu* menu, QObject* receiver, const char* member);
|
||||
|
||||
protected:
|
||||
virtual bool setEdit(int ModNum);
|
||||
virtual void unsetEdit(int ModNum);
|
||||
};
|
||||
|
||||
class ViewProviderPovray : public Gui::ViewProviderDocumentObjectGroup
|
||||
{
|
||||
PROPERTY_HEADER(RaytracingGui::ViewProviderPovray);
|
||||
Q_DECLARE_TR_FUNCTIONS(RaytracingGui::ViewProviderPovray)
|
||||
|
||||
public:
|
||||
ViewProviderPovray();
|
||||
virtual ~ViewProviderPovray();
|
||||
|
||||
bool doubleClicked(void);
|
||||
void setupContextMenu(QMenu* menu, QObject* receiver, const char* member);
|
||||
|
||||
protected:
|
||||
virtual bool setEdit(int ModNum);
|
||||
virtual void unsetEdit(int ModNum);
|
||||
};
|
||||
|
||||
} // namespace RaytracingGui
|
||||
|
||||
#endif // RAYTRACINGGUI_VIEWPROVIDER_H
|
||||
|
Loading…
Reference in New Issue
Block a user