mirror of https://github.com/CGAL/cgal
Add an action to save a scene
This commit is contained in:
parent
636fa74f86
commit
0d376fa5eb
|
|
@ -39,6 +39,7 @@
|
|||
#include <QTreeWidget>
|
||||
#include <QDockWidget>
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
#ifdef QT_SCRIPT_LIB
|
||||
# include <QScriptValue>
|
||||
# ifdef QT_SCRIPTTOOLS_LIB
|
||||
|
|
@ -2303,3 +2304,75 @@ void MainWindow::propagate_action()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionSa_ve_Scene_as_Script_triggered()
|
||||
{
|
||||
QString filename =
|
||||
QFileDialog::getSaveFileName(this,
|
||||
"Save the Scene as a Script File",
|
||||
last_saved_dir,
|
||||
"*.js");
|
||||
std::ofstream os(filename.toUtf8());
|
||||
if(!os)
|
||||
return;
|
||||
std::vector<QString> names;
|
||||
std::vector<QString> loaders;
|
||||
std::vector<QColor> colors;
|
||||
std::vector<int> rendering_modes;
|
||||
for(int i = 0; i < scene->numberOfEntries(); ++i)
|
||||
{
|
||||
Scene_item* item = scene->item(i);
|
||||
QString loader = item->property("loader_name").toString();
|
||||
QString source = item->property("source filename").toString();
|
||||
if(loader.isEmpty())
|
||||
continue;
|
||||
names.push_back(source);
|
||||
loaders.push_back(loader);
|
||||
colors.push_back(item->color());
|
||||
rendering_modes.push_back(item->renderingMode());
|
||||
}
|
||||
//path
|
||||
os << "var camera = \""<<viewer->dumpCameraCoordinates().toStdString()<<"\";\n";
|
||||
os << "var items = [";
|
||||
for(std::size_t i = 0; i< names.size() -1; ++i)
|
||||
{
|
||||
os << "\'" << names[i].toStdString() << "\', ";
|
||||
}
|
||||
os<<"\'"<<names.back().toStdString()<<"\'];\n";
|
||||
|
||||
//plugin
|
||||
os << "var loaders = [";
|
||||
for(std::size_t i = 0; i< names.size() -1; ++i)
|
||||
{
|
||||
os << "\'" << loaders[i].toStdString() << "\', ";
|
||||
}
|
||||
os<<"\'"<<loaders.back().toStdString()<<"\'];\n";
|
||||
|
||||
//color
|
||||
os << "var colors = [";
|
||||
for(std::size_t i = 0; i< names.size() -1; ++i)
|
||||
{
|
||||
os << "[" << colors[i].red() <<", "<< colors[i].green() <<", "<< colors[i].blue() <<"], ";
|
||||
}
|
||||
os<<"[" << colors.back().red() <<", "<< colors.back().green() <<", "<< colors.back().blue() <<"]];\n";
|
||||
|
||||
//rendering mode
|
||||
os << "var rendering_modes = [";
|
||||
for(std::size_t i = 0; i< names.size() -1; ++i)
|
||||
{
|
||||
os << rendering_modes[i] << ", ";
|
||||
}
|
||||
os << rendering_modes.back()<<"];\n";
|
||||
os <<"var initial_scene_size = scene.numberOfEntries;\n";
|
||||
os << "items.forEach(function(item, index, array){\n";
|
||||
os << " main_window.open(item, loaders[index]);\n";
|
||||
os << " var it = scene.item(initial_scene_size+index);\n";
|
||||
os << " var r = colors[index][0];\n";
|
||||
os << " var g = colors[index][1];\n";
|
||||
os << " var b = colors[index][2];\n";
|
||||
os << " it.setRgbColor(r,g,b);\n";
|
||||
os << " it.setRenderingMode(rendering_modes[index]);\n";
|
||||
os << "});\n";
|
||||
os << "viewer.moveCameraToCoordinates(camera, 0.05);\n";
|
||||
os.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -439,6 +439,7 @@ public:
|
|||
#endif
|
||||
private Q_SLOTS:
|
||||
void set_facegraph_mode_adapter(bool is_polyhedron);
|
||||
void on_actionSa_ve_Scene_as_Script_triggered();
|
||||
};
|
||||
|
||||
#endif // ifndef MAINWINDOW_H
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
<addaction name="actionEraseAll"/>
|
||||
<addaction name="actionDuplicate"/>
|
||||
<addaction name="actionSaveAs"/>
|
||||
<addaction name="actionSa_ve_Scene_as_Script"/>
|
||||
<addaction name="actionSaveSnapshot"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionLoadScript"/>
|
||||
|
|
@ -551,6 +552,11 @@
|
|||
<string>Set Transparency &Pass Number</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSa_ve_Scene_as_Script">
|
||||
<property name="text">
|
||||
<string>Sa&ve the Scene as a Script File...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ public Q_SLOTS:
|
|||
virtual void setColor(QColor c) { color_ = c;}
|
||||
//!Setter for the RGB color of the item. Calls setColor(QColor).
|
||||
//!@see setColor(QColor c)
|
||||
void setRbgColor(int r, int g, int b) { setColor(QColor(r, g, b)); }
|
||||
virtual void setRgbColor(int r, int g, int b) { setColor(QColor(r, g, b)); }
|
||||
//!Sets the name of the item.
|
||||
virtual void setName(QString n) { name_ = n; }
|
||||
//!Sets the visibility of the item.
|
||||
|
|
@ -325,6 +325,7 @@ public Q_SLOTS:
|
|||
//!This function is called by `Scene::changeGroup` and should not be
|
||||
//!called manually.
|
||||
virtual void moveToGroup(Scene_group_item* group);
|
||||
void setRenderingMode(int m) { setRenderingMode((RenderingMode)m);}
|
||||
//!Sets the rendering mode of the item.
|
||||
//!@see RenderingMode
|
||||
virtual void setRenderingMode(RenderingMode m) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue