Skip to content

Commit

Permalink
Merge a76005a into 136dfa2
Browse files Browse the repository at this point in the history
  • Loading branch information
rupakbajgain committed Jun 28, 2020
2 parents 136dfa2 + a76005a commit 0ce63ea
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 10 deletions.
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;

virtual std::vector<EntityCoordinate> snapPoints(const geo::Coordinate &coord,
const SimpleSnapConstrain& constrain,
double minDistanceToSnap,
int maxNumberOfSnapPoints) const override;
virtual std::map<unsigned int, lc::geo::Coordinate> dragPoints() const override;
virtual 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;
}

4 changes: 4 additions & 0 deletions lcviewernoqt/drawitems/lcvdrawitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ namespace lc {

virtual void selected(bool selected);

bool cacheable() const;
void cacheable(bool selected);

/**
* @brief Return the entity which is drawn
* @return Entity
Expand All @@ -46,6 +49,7 @@ namespace lc {
private:
bool _selectable;
bool _selected;
bool _cacheable;
};

DECLARE_SHORT_SHARED_PTR(LCVDrawItem)
Expand Down
4 changes: 2 additions & 2 deletions lcviewernoqt/drawitems/lcvpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ LCVPoint::LCVPoint(const lc::entity::Point_CSPtr& coordinate) :
}

void LCVPoint::draw(LcPainter& painter, const LcDrawOptions &options, const lc::geo::Area& rect) const {
painter.point(_point->x(), _point->y(), 3., true);
painter.stroke();
painter.point(_point->x(), _point->y(), 3., true); //This actually strokes circle
painter.stroke(); //fill method is not working in openGL painter
}

lc::entity::CADEntity_CSPtr LCVPoint::entity() const {
Expand Down
15 changes: 14 additions & 1 deletion lcviewernoqt/painters/opengl/openglpainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ void OpenglPainter::move_to(double x, double y)

void OpenglPainter::point(double x, double y, double size, bool deviceCoords)
{
if (deviceCoords){
double x = size;
double y = size;

double zeroCornerX = 0.;
double zeroCornerY = 0.;

device_to_user(&zeroCornerX, &zeroCornerY);
device_to_user(&x, &y);

size = (x - zeroCornerX);
}
circle(x,y,size);
}

void OpenglPainter::line_to(double x, double y)
Expand Down Expand Up @@ -211,4 +224,4 @@ void OpenglPainter::set_dash(const double* dashes, const int num_dashes, double
void OpenglPainter::dash_destroy()
{
_manager->selectDashes(NULL,0,0,false);
}
}

0 comments on commit 0ce63ea

Please sign in to comment.