Permalink
Browse files

Modifications of active layer storage, and prevent layer "0" being re…

…moved
  • Loading branch information...
feragon committed Jun 15, 2017
1 parent dad86e6 commit cbe7278c264b3646d477db50df79f73ffb083e48
@@ -134,11 +134,14 @@ void DXFimpl::addLayer(const DRW_Layer& data) {
lw = getLcLineWidth<lc::MetaLineWidthByValue>(DRW_LW_Conv::lineWidth::width00);
}
auto layer = std::make_shared<lc::Layer>(data.name, lw->width(), col->color());
// If a layer starts with a * it's a special layer we don't process yet
if (data.name.length()>0 && data.name.compare(0,1,"*")) {
auto layer = std::make_shared<lc::Layer>(data.name, lw->width(), col->color());
if(data.name == "0") {
auto al = std::make_shared<lc::operation::ReplaceLayer>(_document, _document->layerByName("0"), layer);
al->execute();
}
else if (data.name.length()>0 && data.name.compare(0,1,"*")) {
auto al = std::make_shared<lc::operation::AddLayer>(_document, layer);
//_builder->appendMetaData(layer);
al->execute();
}
}
@@ -3,8 +3,6 @@
#include "../generic/helpers.h"
#include <cad/meta/icolor.h>
#include <cad/operations/layerops.h>
#include <cadcolors.h>
lc::FileLibs::LibOpenCad::LibOpenCad(lc::Document_SPtr document, lc::operation::Builder_SPtr builder) :
_document(document),
@@ -48,7 +46,13 @@ lc::Layer_SPtr lc::FileLibs::LibOpenCad::addLayer(const CADLayer& data) {
auto color = icolor.intToColor(data.getColor())->color();
auto layer = std::make_shared<Layer>(data.getName(), lw, color);
std::make_shared<lc::operation::AddLayer>(_document, layer)->execute();
if(data.getName() == "0") {
std::make_shared<lc::operation::AddLayer>(_document, layer)->execute();
}
else {
std::make_shared<lc::operation::ReplaceLayer>(_document, _document->layerByName("0"), layer)->execute();
}
return layer;
}
View
@@ -43,7 +43,8 @@ lua/qtbridge.h
lua/luaqobject.h
dialogs/addlayerdialog.h
dialogs/addlinepatterndialog.h
dialogs/linepatternmanager.h)
dialogs/linepatternmanager.h
)
set(UI_srcs
cadmdichild.cpp
@@ -66,7 +67,8 @@ lua/qtbridge.cpp
lua/luaqobject.cpp
dialogs/addlayerdialog.cpp
dialogs/addlinepatterndialog.cpp
dialogs/linepatternmanager.cpp)
dialogs/linepatternmanager.cpp
)
QT5_WRAP_UI(UI_HEADERS
widgets/clicommand.ui
View
@@ -15,9 +15,8 @@
using namespace LCViewer;
CadMdiChild::CadMdiChild(QWidget* parent) :
QWidget(parent) {
QWidget(parent),
_activeLayer(nullptr) {
if (this->objectName().isEmpty()) {
this->setObjectName(QStringLiteral("CadMdiChild"));
@@ -108,6 +107,8 @@ void CadMdiChild::newDocument() {
// Undo manager takes care that we can undo/redo entities within a document
_undoManager = std::make_shared<lc::UndoManagerImpl>(10);
_document->commitProcessEvent().connect<lc::UndoManagerImpl, &lc::UndoManagerImpl::on_CommitProcessEvent>(_undoManager.get());
_activeLayer = _document->layerByName("0");
}
@@ -222,3 +223,11 @@ LCViewer::TempEntities_SPtr CadMdiChild::tempEntities() {
std::vector<lc::entity::CADEntity_SPtr> CadMdiChild::selection() {
return viewer()->documentCanvas()->selection().asVector();
}
lc::Layer_CSPtr CadMdiChild::activeLayer() const {
return _activeLayer;
}
void CadMdiChild::setActiveLayer(const lc::Layer_CSPtr& activeLayer) {
_activeLayer = activeLayer;
}
View
@@ -72,10 +72,18 @@ class CadMdiChild : public QWidget {
LCViewer::LCADViewer* viewer() const {return _viewer;}
std::shared_ptr<LCViewer::Cursor> cursor() const;
/**
* \brief Get container of temporary entities
* \return Temporary entities container
*/
/**
* @brief Get the selected layer
* @return Selected layer
*/
lc::Layer_CSPtr activeLayer() const;
void setActiveLayer(const lc::Layer_CSPtr& activeLayer);
/**
* \brief Get container of temporary entities
* \return Temporary entities container
*/
LCViewer::TempEntities_SPtr tempEntities();
/**
@@ -119,6 +127,7 @@ class CadMdiChild : public QWidget {
lc::StorageManager_SPtr _storageManager;
LCViewer::TempEntities_SPtr _tempEntities;
lc::Layer_CSPtr _activeLayer;
QScrollBar* horizontalScrollBar;
QScrollBar* verticalScrollBar;
View
@@ -189,6 +189,7 @@ void addLCBindings(lua_State *L) {
.addFunction("tempEntities", &CadMdiChild::tempEntities)
.addFunction("undoManager", &CadMdiChild::undoManager)
.addFunction("viewer", &CadMdiChild::viewer)
.addFunction("activeLayer", &CadMdiChild::activeLayer)
.endClass()
.beginClass<LCViewer::Cursor>("Cursor")
@@ -261,8 +262,7 @@ void addLCBindings(lua_State *L) {
.addFactory([]() {
return new Layers();
})
.addFunction("activeLayer", &Layers::activeLayer)
.addFunction("setDocument", &Layers::setDocument, LUA_ARGS(LuaIntf::_opt<lc::Document_SPtr>))
.addFunction("setMdiChild", &Layers::setMdiChild, LUA_ARGS(LuaIntf::_opt<CadMdiChild*>))
.endClass()
.beginExtendClass<LinePatternManager, QDialog>("LinePatternManager")
@@ -75,4 +75,14 @@ lc::Layer_CSPtr LayerModel::layerAt(int row) {
catch(std::out_of_range& e) {
return nullptr;
}
}
unsigned int LayerModel::indexOf(lc::Layer_CSPtr layer) {
for(unsigned int i = 0; i < _layers.size(); i++) {
if(_layers[i] == layer) {
return i;
}
}
return 0;
}
@@ -38,6 +38,13 @@ class LayerModel : public QAbstractTableModel {
*/
lc::Layer_CSPtr layerAt(int row);
/**
* @brief Give the index of the given layer
* @param layer
* @return Index of layer
*/
unsigned int indexOf(lc::Layer_CSPtr layer);
/**
* \brief Get number of layers
* \return Number of layers
@@ -56,7 +63,6 @@ class LayerModel : public QAbstractTableModel {
private:
std::vector<lc::Layer_CSPtr> _layers;
lc::Layer_CSPtr _selectedLayer;
QIcon _editIcon;
QIcon _lockedIcon;
Oops, something went wrong.

0 comments on commit cbe7278

Please sign in to comment.