Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings & surface modelisation #39

Merged
merged 14 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion schnapps/core/control_dock_map_tab_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
</size>
</property>
<property name="currentIndex">
<number>4</number>
<number>1</number>
</property>
<widget class="QWidget" name="dartInfo">
<attribute name="title">
Expand Down
34 changes: 21 additions & 13 deletions schnapps/core/map_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class SCHNAPPS_CORE_API MapHandlerGen : public QObject
friend class View;

public:

EIGEN_MAKE_ALIGNED_OPERATOR_NEW

template<typename T>
using ChunkArrayContainer = MapBaseData::ChunkArrayContainer<T>;
using ChunkArrayGen = cgogn::MapBaseData::ChunkArrayGen;
Expand Down Expand Up @@ -469,30 +471,32 @@ class MapHandler : public MapHandlerGen
virtual void foreach_cell(CellType ct, const std::function<void(cgogn::Dart)>& func) const override
{
const cgogn::Orbit orb = orbit(ct);
switch (orb) {
switch (orb)
{
case CDart::ORBIT: get_map()->foreach_cell([&](CDart d) { func(d.dart); }); break;
case Vertex::ORBIT: get_map()->foreach_cell([&](Vertex v) { func(v.dart); }); break;
case Edge::ORBIT: get_map()->foreach_cell([&](Edge e) { func(e.dart); }); break;
case Face::ORBIT: get_map()->foreach_cell([&](Face f) { func(f.dart); }); break;
case Volume::ORBIT: get_map()->foreach_cell([&](Volume w) { func(w.dart); }); break;
default: break;
}
}
}

virtual void parallel_foreach_cell(CellType ct, const std::function<void(cgogn::Dart,uint32)>& func) const override
{
const cgogn::Orbit orb = orbit(ct);
switch (orb) {
switch (orb)
{
case CDart::ORBIT: get_map()->parallel_foreach_cell([&](CDart d, uint32 th) { func(d.dart, th); }); break;
case Vertex::ORBIT: get_map()->parallel_foreach_cell([&](Vertex v, uint32 th) { func(v.dart, th); }); break;
case Edge::ORBIT: get_map()->parallel_foreach_cell([&](Edge e, uint32 th) { func(e.dart, th); }); break;
case Face::ORBIT: get_map()->parallel_foreach_cell([&](Face f, uint32 th) { func(f.dart, th); }); break;
case Volume::ORBIT: get_map()->parallel_foreach_cell([&](Volume w, uint32 th) { func(w.dart, th); }); break;
default: break;
}
}
}

virtual uint32 embedding(cgogn::Dart d,CellType ct) const override
virtual uint32 embedding(cgogn::Dart d, CellType ct) const override
{
return get_map()->embedding(d, orbit(ct));
}
Expand All @@ -501,15 +505,16 @@ class MapHandler : public MapHandlerGen
{
const cgogn::Orbit orb = orbit(ct);
const auto* map = get_map();
switch (orb) {
switch (orb)
{
case CDart::ORBIT: return d == e;
case Vertex::ORBIT: return map->same_cell(Vertex(d), Vertex(e));
case Edge::ORBIT: return map->same_cell(Edge(d), Edge(e));
case Face::ORBIT: return map->same_cell(Face(d), Face(e));
case Volume::ORBIT: return map->same_cell(Volume(d), Volume(e));
default:
return false;
}
}
}

virtual std::pair<cgogn::Dart, cgogn::Dart> vertices(cgogn::Dart edge) const override
Expand Down Expand Up @@ -561,10 +566,13 @@ class MapHandler : public MapHandlerGen
void set_bb_vertex_attribute(const QString& attribute_name) override
{
bb_vertex_attribute_ = get_map()->template get_attribute<VEC3, Vertex::ORBIT>(attribute_name.toStdString());
compute_bb();
this->update_bb_drawer();
emit(bb_vertex_attribute_changed(attribute_name));
emit(bb_changed());
if (bb_vertex_attribute_.is_valid())
{
compute_bb();
this->update_bb_drawer();
emit(bb_vertex_attribute_changed(attribute_name));
emit(bb_changed());
}
}

void check_bb_vertex_attribute(cgogn::Orbit orbit, const QString& attribute_name) override
Expand Down Expand Up @@ -670,8 +678,6 @@ class MapHandler : public MapHandlerGen
return res;
}

protected:

/*********************************************************
* MANAGE VBOs
*********************************************************/
Expand Down Expand Up @@ -881,6 +887,8 @@ class MapHandler : public MapHandlerGen
}
}

protected:

/*********************************************************
* MANAGE CELLS SETS
*********************************************************/
Expand Down
6 changes: 3 additions & 3 deletions schnapps/core/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ namespace schnapps

const QVariant Plugin::get_setting(const QString& name) const
{
return get_schnapps()->get_setting(this->get_name(), name);
return schnapps_->get_setting(this->get_name(), name);
}

QVariant* Plugin::add_setting(const QString& name, const QVariant& default_value)
QVariant Plugin::add_setting(const QString& name, const QVariant& default_value)
{
return get_schnapps()->add_setting(this->get_name(), name, default_value);
return schnapps_->add_setting(this->get_name(), name, default_value);
}

Plugin::~Plugin()
Expand Down
3 changes: 2 additions & 1 deletion schnapps/core/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public slots:
inline SCHNApps* get_schnapps() const { return schnapps_; }

const QVariant get_setting(const QString& name) const;
QVariant* add_setting(const QString& name, const QVariant& default_value);

QVariant add_setting(const QString& name, const QVariant& default_value);

private:

Expand Down
18 changes: 8 additions & 10 deletions schnapps/core/schnapps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,25 @@ SCHNApps::SCHNApps(const QString& app_path, SCHNAppsWindow* window) :
root_splitter_->addWidget(first_view_);

#ifdef WIN32
register_plugins_directory(app_path);
register_plugins_directory(app_path_);
#else
register_plugins_directory(app_path + QString("/../lib"));
register_plugins_directory(app_path_ + QString("/../lib"));
#endif
settings_ = Settings::from_file("settings.json");

settings_ = Settings::from_file(app_path_ + QString("/../lib/settings.json"));
settings_->set_widget(window->settings_widget_.get());
for (const QVariant& plugin_dir_v : get_core_setting("Plugins paths").toList())
this->register_plugins_directory(plugin_dir_v.toString());

for (const QVariant& plugin_v : get_core_setting("Load modules").toList())
this->enable_plugin(plugin_v.toString());
}

SCHNApps::~SCHNApps()
{
settings_->to_file("settings.json");
settings_->to_file(app_path_ + QString("/../lib/settings.json"));
// first safely unload every plugins (this has to be done before the views get deleted)
while(!plugins_.empty())
{
while (!plugins_.empty())
this->disable_plugin(plugins_.begin()->first);
}
}

/*********************************************************
Expand Down Expand Up @@ -342,11 +340,11 @@ MapHandlerGen* SCHNApps::add_map(const QString &name, unsigned int dimension)
switch(dimension)
{
case 2 : {
maps_.insert(std::make_pair(final_name, cgogn::make_unique<MapHandler<CMap2>>(final_name, this)));
maps_.insert(std::make_pair(final_name, cgogn::make_unique<CMap2Handler>(final_name, this)));
break;
}
case 3 : {
maps_.insert(std::make_pair(final_name, cgogn::make_unique<MapHandler<CMap3>>(final_name, this)));
maps_.insert(std::make_pair(final_name, cgogn::make_unique<CMap3Handler>(final_name, this)));
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions schnapps/core/schnapps.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,14 @@ public slots:

void schnapps_closing();


public:

inline const QVariant get_setting(const QString& module_name, const QString& name) const
{
return settings_->get_setting(module_name, name);
}

inline QVariant* add_setting(const QString& module_name, const QString& name, const QVariant& val)
inline QVariant add_setting(const QString& module_name, const QString& name, const QVariant& val)
{
return settings_->add_setting(module_name,name,val);
}
Expand Down
38 changes: 16 additions & 22 deletions schnapps/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,38 @@ std::unique_ptr<Settings> Settings::from_file(const QString& setting_filename)
QFile setting_file(setting_filename);
if (setting_file.exists() && setting_file.open(QIODevice::ReadOnly))
{
QByteArray data = setting_file.readAll();
QByteArray data = setting_file.readAll();

QJsonParseError parse_error;
QJsonDocument doc = QJsonDocument::fromJson(data, &parse_error);
if (parse_error.error != QJsonParseError::NoError)
{
cgogn_log_warning("Settings(const QString&)") << "Error while reading the file \"" << setting_filename.toStdString() << "\". Error is : \"" << parse_error.errorString().toStdString() << "\".";
} else {
else
cgogn_log_info("Settings(const QString&)") << "Loaded setting file \"" << setting_filename.toStdString() << "\".";
}
const auto obj = doc.object();
for(auto it = obj.constBegin(); it != obj.constEnd(); ++it)
for (auto it = obj.constBegin(); it != obj.constEnd(); ++it)
settings->add_module(it.key(), it.value().toObject().toVariantMap());
} else {
cgogn_log_warning("Settings::from_file()") << "Unable to read the file \"" << setting_filename.toStdString() << "\".";
}
else
cgogn_log_warning("Settings::from_file()") << "Unable to read the file \"" << setting_filename.toStdString() << "\".";

return settings;
}

void Settings::add_module(const QString& module_name, const QVariantMap& module)
{
if (!map_.contains(module_name))
{
map_[module_name] = module;
}
}

Settings::~Settings()
{}

QVariant* Settings::add_setting(const QString& module_name, const QString& setting_name, const QVariant& value)
QVariant Settings::add_setting(const QString& module_name, const QString& setting_name, const QVariant& value)
{
if (!map_[module_name].contains(setting_name))
map_[module_name][setting_name] = value;
return &map_[module_name][setting_name];
return map_[module_name][setting_name];
}

const QVariant Settings::get_setting(const QString& module_name, const QString& setting_name) const
Expand All @@ -86,9 +83,9 @@ const QVariant Settings::get_setting(const QString& module_name, const QString&
return setting_it.value();
else
cgogn_log_debug("Settings::get_setting") << "Unable to find setting \"" << setting_name.toStdString() << "\" in module \"" << module_name.toStdString() << "\".";
} else {
cgogn_log_debug("Settings::get_setting") << "Unable to find module \"" << module_name.toStdString() << "\".";
}
else
cgogn_log_debug("Settings::get_setting") << "Unable to find module \"" << module_name.toStdString() << "\".";
return QVariant();
}

Expand All @@ -103,9 +100,9 @@ void Settings::to_file(const QString& filename)
obj[it.key()] = QJsonObject::fromVariantMap(it.value());
QJsonDocument doc(obj);
setting_file.write(doc.toJson());
} else {
cgogn_log_info("Settings::to_file()") << "Unable to write in the file \"" << filename.toStdString() << "\".";
}
else
cgogn_log_info("Settings::to_file()") << "Unable to write in the file \"" << filename.toStdString() << "\".";
}

void Settings::set_widget(QWidget* widget)
Expand All @@ -118,21 +115,18 @@ void Settings::set_widget(QWidget* widget)
void Settings::setting_changed(const QString& module_name, const QString& name, const QVariant& value)
{
if (!map_.contains(module_name))
{
cgogn_log_debug("Settings::setting_changed") << "Trying to modify a setting of a non-existing module \"" << module_name.toStdString() << "\".";
} else
else
{
if (!map_[module_name].contains(name))
{
cgogn_log_debug("Settings::setting_changed") << "Trying to modify a non-existing setting \"" << name.toStdString() << "\" of the module \"" << module_name.toStdString() << "\".";
} else {
else
{
QVariant& v = map_[module_name][name];
if (v.type() != value.type())
{
cgogn_log_debug("Settings::setting_changed") << "Cannot replace a setting of type \"" << v.typeName() << "\" by another setting of type \"" << value.typeName() << "\".";
} else {
else
v = value;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions schnapps/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class SCHNAPPS_CORE_API Settings : public QObject
* @param module_name
* @param setting_name
* @param value
* @return a pointer to the place where the data is stored.
* @return the setting value
*/
QVariant* add_setting(const QString& module_name, const QString& setting_name, const QVariant& value);
QVariant add_setting(const QString& module_name, const QString& setting_name, const QVariant& value);
const QVariant get_setting(const QString& module_name, const QString& setting_name) const;

void to_file(const QString& filename);
Expand Down
1 change: 1 addition & 0 deletions schnapps/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <cgogn/core/utils/numerics.h>
#include <cgogn/geometry/types/geometry_traits.h>
#include <unsupported/Eigen/AlignedVector3>

namespace cgogn
{

Expand Down
2 changes: 2 additions & 0 deletions schnapps/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ add_subdirectory(surface_differential_properties)
add_subdirectory(surface_render)
add_subdirectory(surface_render_vector)
add_subdirectory(surface_render_scalar)
add_subdirectory(surface_modelisation)
add_subdirectory(volume_render)
add_subdirectory(image)
add_subdirectory(meshgen)
add_subdirectory(extract_surface)
add_subdirectory(attribute_editor)
add_subdirectory(volume_modelisation)
add_subdirectory(merge_plugin)
add_subdirectory(shallow_water)
add_subdirectory(empty_plugin)
1 change: 0 additions & 1 deletion schnapps/plugins/empty_plugin/dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#ifndef SCHNAPPS_PLUGIN_EMPTY_PLUGIN_DLL_H_
#define SCHNAPPS_PLUGIN_EMPTY_PLUGIN_DLL_H_


#ifdef WIN32
#ifndef SCHNAPPS_PLUGIN_EMPTY_PLUGIN_API
#if defined SCHNAPPS_PLUGIN_EMPTY_PLUGIN_DLL_EXPORT
Expand Down
9 changes: 5 additions & 4 deletions schnapps/plugins/empty_plugin/empty_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ namespace schnapps
namespace plugin_empty_plugin
{

EmptyPlugin::EmptyPlugin()
Plugin_EmptyPlugin::Plugin_EmptyPlugin()
{}

EmptyPlugin::~EmptyPlugin()
Plugin_EmptyPlugin::~Plugin_EmptyPlugin()
{}

bool EmptyPlugin::enable()
bool Plugin_EmptyPlugin::enable()
{
return true;
}

void EmptyPlugin::disable()
void Plugin_EmptyPlugin::disable()
{
}

} // namespace plugin_empty_plugin

} // namespace schnapps
Loading