Skip to content

Commit

Permalink
Merge ebf47c2 into 136dfa2
Browse files Browse the repository at this point in the history
  • Loading branch information
rupakbajgain committed Jun 28, 2020
2 parents 136dfa2 + ebf47c2 commit c3647a8
Show file tree
Hide file tree
Showing 17 changed files with 238 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lcUI/lcadpaperviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace lc::ui;
using namespace lc::viewer;

#define PAPER_WIDTH 300
#define PAPER_HEIGHT 200
#define PAPER_HEIGHT -200

LCADPaperViewer::LCADPaperViewer(QWidget* parent,int id = 0):LCADViewer(parent),_id(id){
_gradientBackground = std::make_shared<drawable::PaperBackground>(PAPER_WIDTH, PAPER_HEIGHT);
Expand Down Expand Up @@ -47,4 +47,4 @@ void LCADPaperViewer::setDocument(std::shared_ptr<lc::storage::Document> documen

void LCADPaperViewer::onMouseMoveEvent(){
emit setActive(_id);
};
};
11 changes: 11 additions & 0 deletions lcUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ void MainWindow::ConnectInputEvents()
QObject::connect(findMenuItemByObjectName("actionSelect_All"), &QAction::triggered, this, &MainWindow::selectAll);
QObject::connect(findMenuItemByObjectName("actionSelect_None"), &QAction::triggered, this, &MainWindow::selectNone);
QObject::connect(findMenuItemByObjectName("actionInvert_Selection"), &QAction::triggered, this, &MainWindow::invertSelection);
QObject::connect(findMenuItemByObjectName("actionClear_Undoable_Stack"), &QAction::triggered, this, &MainWindow::clearUndoableStack);
}

/* Menu functions */
Expand Down Expand Up @@ -534,24 +535,34 @@ void MainWindow::openFile()
void MainWindow::undo()
{
_cadMdiChild.undoManager()->undo();
_cadMdiChild.viewer()->update();
}

void MainWindow::clearUndoableStack()
{
_cadMdiChild.undoManager()->removeUndoables();
}

void MainWindow::redo()
{
_cadMdiChild.undoManager()->redo();
_cadMdiChild.viewer()->update();
}

void MainWindow::selectAll()
{
_cadMdiChild.viewer()->docCanvas()->selectAll();
_cadMdiChild.viewer()->update();
}

void MainWindow::selectNone()
{
_cadMdiChild.viewer()->docCanvas()->removeSelection();
_cadMdiChild.viewer()->update();
}

void MainWindow::invertSelection()
{
_cadMdiChild.viewer()->docCanvas()->inverseSelection();
_cadMdiChild.viewer()->update();
}
1 change: 1 addition & 0 deletions lcUI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ namespace lc
void selectAll();
void selectNone();
void invertSelection();
void clearUndoableStack();

signals:
void point(lc::geo::Coordinate coordinate);
Expand Down
6 changes: 6 additions & 0 deletions lcUI/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<addaction name="actionClear_Undoable_Stack"/>
<addaction name="separator"/>
<addaction name="actionPolyline"/>
<addaction name="actionPoint"/>
<addaction name="actionSpline"/>
</widget>
</widget>
Expand Down Expand Up @@ -289,6 +290,11 @@
<string>&amp;Polyline</string>
</property>
</action>
<action name="actionPoint">
<property name="text">
<string>P&amp;oint</string>
</property>
</action>
<action name="actionSpline">
<property name="text">
<string>&amp;Spline</string>
Expand Down
76 changes: 76 additions & 0 deletions lcUI/ui/icons/point.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions lcUI/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<addaction name="menuEllipse"/>
<addaction name="menuDimension"/>
<addaction name="actionPolyline"/>
<addaction name="actionPoint"/>
<addaction name="actionSpline"/>
</widget>
<addaction name="menuDemo_Project"/>
Expand Down Expand Up @@ -294,6 +295,11 @@
<string>&amp;Polyline</string>
</property>
</action>
<action name="actionPoint">
<property name="text">
<string>P&amp;oint</string>
</property>
</action>
<action name="actionSpline">
<property name="text">
<string>&amp;Spline</string>
Expand Down
1 change: 1 addition & 0 deletions lcUI/ui/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<file alias="snap_grid.svg">icons/snap_grid.svg</file>
<file alias="snap_intersection.svg">icons/snap_intersection.svg</file>
<file alias="snap_middle.svg">icons/snap_middle.svg</file>
<file alias="point.svg">icons/point.svg</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion lcUILua/createActions/createOperations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function CreateOperations:_init(builder, step)

self.prevEntity = nil
if(builder ~= nil) then
self.builder = builder() -- is it working?
self.builder = builder()
end

self.step = step
Expand Down
39 changes: 39 additions & 0 deletions lcUILua/createActions/pointoperations.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
PointOperations = {
command_line = "POINT",
icon = "point.svg",
descreption = "Point",
menu_actions = {
default = "actionPoint"
}
}
PointOperations.__index = PointOperations

setmetatable(PointOperations, {
__index = CreateOperations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})

function PointOperations:_init()
CreateOperations._init(self, lc.builder.PointBuilder, "enterPoint")
mainWindow:cliCommand():commandActive(true)
message("Add a new point")
end

--function PointOperations:_init_default()
-- message("<b>POINT</b>")
-- message("Provide Point")
-- self.step = "enterPoint"
--end

function PointOperations:enterPoint(eventName, data)
if(eventName == "mouseMove") then
self.builder:setCoordinate(data["position"])
elseif (eventName == "point") then
self.builder:setCoordinate(data["position"])
self:createEntity()
end
end
2 changes: 1 addition & 1 deletion lckernel/cad/primitive/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ CADEntity_CSPtr Line::setDragPoints(std::map<unsigned int, lc::geo::Coordinate>
//A point was not in the map, don't change the entity
return shared_from_this();
}
}
}
43 changes: 43 additions & 0 deletions lckernel/cad/primitive/point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,47 @@ CADEntity_CSPtr Point::modify(meta::Layer_CSPtr layer, const meta::MetaInfo_CSPt
return newEntity;
}

// additional options
geo::Coordinate Point::nearestPointOnPath(const Coordinate& coord) const {
return geo::Coordinate(this->x(), this->y());
}

geo::Coordinate Point::nearestPointOnEntity(const Coordinate& coord) const {
return geo::Coordinate(this->x(), this->y());
}


std::vector<EntityCoordinate> Point::snapPoints(const geo::Coordinate& coord,
const SimpleSnapConstrain & constrain,
double minDistanceToSnap,
int maxNumberOfSnapPoints) const {
std::vector<EntityCoordinate> points;
if ((bool) (constrain.constrain() & SimpleSnapConstrain::LOGICAL)) {
points.emplace_back(geo::Coordinate(this->x(), this->y()),0);
}

Snapable::snapPointsCleanup(points, coord, maxNumberOfSnapPoints, minDistanceToSnap);
return points;
}

std::map<unsigned int, lc::geo::Coordinate> Point::dragPoints() const {
std::map<unsigned int, lc::geo::Coordinate> points;
points[0]=(geo::Coordinate(this->x(), this->y()));
return points;
}

CADEntity_CSPtr Point::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
try {
auto newEntity = std::make_shared<Point>(dragPoints.at(0),
layer(),
metaInfo(),
block()
);
newEntity->setID(this->id());
return newEntity;
}
catch(const std::out_of_range& e) {
//A point was not in the map, don't change the entity
return shared_from_this();
}
}
14 changes: 13 additions & 1 deletion lckernel/cad/primitive/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
#include "cad/base/cadentity.h"
#include "cad/vo/entitycoordinate.h"

#include "cad/interface/snapable.h"
#include "cad/interface/draggable.h"

#include <cad/meta/layer.h>

#include <cad/builders/point.h>

namespace lc {
namespace entity {
class Point : public std::enable_shared_from_this<Point>, public CADEntity, public geo::Coordinate, virtual public Visitable {
class Point : public std::enable_shared_from_this<Point>, public CADEntity, public geo::Coordinate, public Snapable, public Draggable, virtual public Visitable {
friend class builder::PointBuilder;

public:
Expand Down Expand Up @@ -87,6 +90,15 @@ namespace lc {

virtual CADEntity_CSPtr modify(meta::Layer_CSPtr layer, meta::MetaInfo_CSPtr metaInfo, meta::Block_CSPtr block) const override;

std::vector<EntityCoordinate> snapPoints(const geo::Coordinate &coord,
const SimpleSnapConstrain& constrain,
double minDistanceToSnap,
int maxNumberOfSnapPoints) const override;
std::map<unsigned int, lc::geo::Coordinate> dragPoints() const override;
CADEntity_CSPtr setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const override;
geo::Coordinate nearestPointOnPath(const Coordinate& coord) const;
geo::Coordinate nearestPointOnEntity(const Coordinate& coord) const;

public:
virtual void accept(GeoEntityVisitor &v) const override { v.visit(*this); }

Expand Down
9 changes: 6 additions & 3 deletions lcviewernoqt/documentcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void DocumentCanvas::render(LcPainter& painter, PainterType type) {
}
});
for(const auto& di: visibleDrawables) {
if(painter.isCachingEnabled() )
if(painter.isCachingEnabled() && di->cacheable())
{
if(painter.isEntityCached( (di->entity())->id() ) == true)
{
Expand All @@ -229,7 +229,7 @@ void DocumentCanvas::render(LcPainter& painter, PainterType type) {
else
{
drawEntity(painter, di);
cacheEntity((di->entity())->id(), di);
cacheEntity((di->entity())->id(), di);
}
}
else
Expand Down Expand Up @@ -688,8 +688,11 @@ LCVDrawItem_SPtr DocumentCanvas::asDrawable(const lc::entity::CADEntity_CSPtr& e
// Add 'Point' or 'Coordinate'
auto coord = std::dynamic_pointer_cast<const lc::entity::Point>(entity);

// Point cannot be cached since it change size(constant size)
if (coord != nullptr) {
return std::make_shared<LCVPoint>(coord);
auto di = std::make_shared<LCVPoint>(coord);
di->cacheable(false);
return di;
}

// Add 'DimRadial'
Expand Down
12 changes: 11 additions & 1 deletion lcviewernoqt/drawitems/lcvdrawitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ using namespace lc::viewer;

LCVDrawItem::LCVDrawItem(const lc::entity::CADEntity_CSPtr& entity, bool selectable) :
_selectable(selectable),
_selected(false) {
_selected(false),
_cacheable(true) {

}

Expand All @@ -19,3 +20,12 @@ bool LCVDrawItem::selected() const {
void LCVDrawItem::selected(bool selected) {
_selected = selected;
}

bool LCVDrawItem::cacheable() const {
return _cacheable;
}

void LCVDrawItem::cacheable(bool cache) {
_cacheable = cache;
}

0 comments on commit c3647a8

Please sign in to comment.