Skip to content

Commit

Permalink
polyline: experimental, create from selected entities
Browse files Browse the repository at this point in the history
  • Loading branch information
dxli committed Jan 3, 2016
1 parent 6713e7d commit 6b5125b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
34 changes: 30 additions & 4 deletions librecad/src/actions/rs_actionpolylinesegment.cpp
Expand Up @@ -50,6 +50,28 @@ RS_ActionPolylineSegment::RS_ActionPolylineSegment(RS_EntityContainer& container
void RS_ActionPolylineSegment::init(int status) {
RS_ActionInterface::init(status);
targetEntity = nullptr;
//Experimental feature: trigger action, if already has selected entities
if (container->countSelected(true, entityType)) {
//find a selected entity
//TODO, find a better starting point
for (RS_Entity* e = container->firstEntity(RS2::ResolveAllButInserts);
e;
e = container->nextEntity(RS2::ResolveAllButInserts)) {
if (e->isSelected() &&
std::count(entityType.begin(), entityType.end(), e->rtti())) {
targetEntity = e;
break;
}
}
if (targetEntity) {
convertPolyline(targetEntity, true);
RS_DIALOGFACTORY->commandMessage(tr("Polyline created"));
graphicView->redraw();
RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
finish(false);
return;
}
}
}

/**
Expand Down Expand Up @@ -116,18 +138,22 @@ RS_Vector RS_ActionPolylineSegment::appendPol(RS_Polyline *current, RS_Polyline
*
* @author Rallaz
*/
bool RS_ActionPolylineSegment::convertPolyline(RS_Entity* selectedEntity) {
bool RS_ActionPolylineSegment::convertPolyline(RS_Entity* selectedEntity, bool useSelected) {

RS_DEBUG->print("RS_ActionPolylineSegment::convertPolyline");

QList<RS_Entity*> remaining;
QList<RS_Entity*> completed;
RS_Vector start = selectedEntity->getStartpoint();
RS_Vector end = selectedEntity->getEndpoint();
completed.append(selectedEntity);
if (!useSelected || (selectedEntity && selectedEntity->isSelected()))
completed.append(selectedEntity);
//get list with useful entities
for (unsigned i=0; i<container->count(); ++i) {
RS_Entity* e1 = container->entityAt(i);

for (RS_Entity* e1 = container->firstEntity(RS2::ResolveAllButInserts);
e1;
e1 = container->nextEntity(RS2::ResolveAllButInserts)) {
if (useSelected && !e1->isSelected()) continue;
if (e1->isLocked() || !e1->isVisible() || e1 == selectedEntity) continue;
if (e1->rtti()==RS2::EntityLine || e1->rtti()==RS2::EntityArc
|| e1->rtti()==RS2::EntityPolyline) {
Expand Down
4 changes: 3 additions & 1 deletion librecad/src/actions/rs_actionpolylinesegment.h
Expand Up @@ -56,7 +56,9 @@ class RS_ActionPolylineSegment : public RS_PreviewActionInterface {

virtual void updateMouseButtonHints();
virtual void updateMouseCursor();
virtual bool convertPolyline(RS_Entity* selectedEntity);
//! create polyline from segments
//! @param useSelected only create from selected entities
virtual bool convertPolyline(RS_Entity* selectedEntity, bool useSelected = false);

private:
RS_Vector appendPol(RS_Polyline *current, RS_Polyline *toAdd, bool reversed);
Expand Down

0 comments on commit 6b5125b

Please sign in to comment.