| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #include "rs_selection.h" |
| |
|
| | #include "lc_containertraverser.h" |
| | #include "lc_graphicviewport.h" |
| | #include "qc_applicationwindow.h" |
| | #include "qg_dialogfactory.h" |
| | #include "rs_dialogfactory.h" |
| | #include "rs_entitycontainer.h" |
| | #include "rs_information.h" |
| | #include "rs_insert.h" |
| | #include "rs_layer.h" |
| | #include "rs_line.h" |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | RS_Selection::RS_Selection( |
| | RS_EntityContainer &container, |
| | LC_GraphicViewport *graphicView): |
| | m_container{&container}, m_graphic{container.getGraphic()}, m_graphicView{graphicView}{ |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_Selection::selectSingle(RS_Entity *e){ |
| | if (e && (!(e->getLayer() && e->getLayer()->isLocked()))){ |
| |
|
| | e->toggleSelected(); |
| |
|
| | if (m_graphicView){ |
| | if (e->isSelected() && (e->rtti() == RS2::EntityInsert)){ |
| | const RS_Block *selectedBlock = dynamic_cast<RS_Insert *>(e)->getBlockForInsert(); |
| |
|
| | if (selectedBlock != nullptr){ |
| | |
| | QC_ApplicationWindow::getAppWindow()->showBlockActivated(selectedBlock); |
| | |
| | QG_DIALOGFACTORY->displayBlockName(selectedBlock->getName(), true); |
| | } |
| | } else { |
| | QG_DIALOGFACTORY->displayBlockName("", false); |
| | } |
| | m_graphicView->notifyChanged(); |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_Selection::selectAll(bool select){ |
| | if (m_graphicView){ |
| | for (auto e: *m_container) { |
| | if (e && e->isVisible()){ |
| | e->setSelected(select); |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | } |
| | } |
| | m_graphicView->notifyChanged(); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_Selection::invertSelection(){ |
| | for (auto e: *m_container) { |
| | if (e && e->isVisible()){ |
| | e->toggleSelected(); |
| | } |
| | } |
| |
|
| | m_graphicView->notifyChanged(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void RS_Selection::selectWindow( |
| | enum RS2::EntityType typeToSelect, const RS_Vector &v1, const RS_Vector &v2, |
| | bool select, bool cross){ |
| | m_container->selectWindow(typeToSelect, v1, v2, select, cross); |
| | m_graphicView->notifyChanged(); |
| | } |
| |
|
| | void RS_Selection::selectWindow(const QList<RS2::EntityType> &typesToSelect, const RS_Vector &v1, const RS_Vector &v2, |
| | bool select, bool cross){ |
| |
|
| | m_container->selectWindow(typesToSelect, v1, v2, select, cross); |
| | m_graphicView->notifyChanged(); |
| | } |
| |
|
| | void RS_Selection::selectIntersected(RS_Entity* entity, bool select) { |
| | if (entity->isAtomic()) { |
| | selectIntersectedAtomic(entity, select); |
| | } |
| | else if (entity->isContainer()) { |
| | selectIntersectedContainer(entity, select); |
| | } |
| | } |
| |
|
| | void RS_Selection::selectIntersectedContainer(RS_Entity* entity, bool select) { |
| | auto* cont = dynamic_cast<RS_EntityContainer*>(entity); |
| | auto containerEntities = lc::LC_ContainerTraverser{*cont, RS2::ResolveAll}.entities(); |
| |
|
| | bool inters; |
| | for (auto e : *m_container) { |
| | if (e == nullptr || e == entity || !e->isVisible()) { |
| | continue; |
| | } |
| | inters = false; |
| |
|
| | |
| | if (e->isContainer()) { |
| | auto* ec = static_cast<RS_EntityContainer*>(e); |
| | if (entity->getParent() == e) { |
| | continue; |
| | } |
| | for (RS_Entity* e2 : lc::LC_ContainerTraverser{*ec, RS2::ResolveAll}.entities()) { |
| | for (RS_Entity* e3 : containerEntities) { |
| | RS_VectorSolutions sol = RS_Information::getIntersection(e3, e2, true); |
| | if (sol.hasValid()) { |
| | inters = true; |
| | break; |
| | } |
| | } |
| | } |
| | } |
| | else { |
| | for (RS_Entity* e2 : containerEntities) { |
| | RS_VectorSolutions sol = RS_Information::getIntersection(e2, e, true); |
| | if (sol.hasValid()) { |
| | inters = true; |
| | break; |
| | } |
| | } |
| | } |
| | if (inters) { |
| | e->setSelected(select); |
| | } |
| | } |
| | m_graphicView->notifyChanged(); |
| | } |
| |
|
| | void RS_Selection::selectIntersectedAtomic(RS_Entity* entity, bool select) { |
| | bool inters; |
| |
|
| | for (auto e: *m_container) { |
| | if (e != nullptr && e->isVisible()){ |
| | inters = false; |
| |
|
| | |
| | if (e->isContainer()){ |
| | auto *ec = static_cast<RS_EntityContainer*>(e); |
| | if (entity->getParent() == e) { |
| | continue; |
| | } |
| | for(RS_Entity* e2: lc::LC_ContainerTraverser{*ec, RS2::ResolveAll}.entities()) { |
| | RS_VectorSolutions sol = RS_Information::getIntersection(entity, e2, true); |
| | if (sol.hasValid()){ |
| | inters = true; |
| | } |
| | } |
| | } else { |
| | RS_VectorSolutions sol = RS_Information::getIntersection(entity, e, true); |
| | if (sol.hasValid()){ |
| | inters = true; |
| | } |
| | } |
| | if (inters){ |
| | e->setSelected(select); |
| | } |
| | } |
| | } |
| | m_graphicView->notifyChanged(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void RS_Selection::selectIntersected(const RS_Vector &v1, const RS_Vector &v2, bool select){ |
| | RS_Line line{v1, v2}; |
| | selectIntersected(&line, select); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void RS_Selection::selectContour(RS_Entity *e){ |
| |
|
| | if (e == nullptr){ |
| | return; |
| | } |
| |
|
| | if (!e->isAtomic()){ |
| | return; |
| | } |
| |
|
| | bool select = !e->isSelected(); |
| | auto *ae = (RS_AtomicEntity *) e; |
| | RS_Vector p1 = ae->getStartpoint(); |
| | RS_Vector p2 = ae->getEndpoint(); |
| | bool found = false; |
| |
|
| | |
| | e->setSelected(select); |
| |
|
| | do { |
| | found = false; |
| | |
| | for (auto en: *m_container) { |
| |
|
| | if (en && en->isVisible() && |
| | en->isAtomic() && en->isSelected() != select && |
| | (!(en->getLayer() && en->getLayer()->isLocked()))){ |
| |
|
| | ae = (RS_AtomicEntity *) en; |
| | bool doit = false; |
| |
|
| | |
| | if (ae->getStartpoint().distanceTo(p1) < 1.0e-4){ |
| | doit = true; |
| | p1 = ae->getEndpoint(); |
| | } |
| |
|
| | |
| | else if (ae->getEndpoint().distanceTo(p1) < 1.0e-4){ |
| | doit = true; |
| | p1 = ae->getStartpoint(); |
| | } |
| |
|
| | |
| | else if (ae->getStartpoint().distanceTo(p2) < 1.0e-4){ |
| | doit = true; |
| | p2 = ae->getEndpoint(); |
| | } |
| |
|
| | |
| | else if (ae->getEndpoint().distanceTo(p2) < 1.0e-4){ |
| | doit = true; |
| | p2 = ae->getStartpoint(); |
| | } |
| |
|
| | if (doit){ |
| | ae->setSelected(select); |
| | found = true; |
| | } |
| | } |
| | } |
| | } while (found); |
| | m_graphicView->notifyChanged(); |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_Selection::selectLayer(RS_Entity *e){ |
| | if (e == nullptr) |
| | return; |
| |
|
| | bool select = !e->isSelected(); |
| | RS_Layer *layer = e->getLayer(true); |
| | if (layer == nullptr) { |
| | return; |
| | } |
| |
|
| | QString layerName = layer->getName(); |
| | selectLayer(layerName, select); |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_Selection::selectLayer(const QString &layerName, bool select){ |
| | for (auto en: *m_container) { |
| | |
| | if (en && en->isVisible() && |
| | en->isSelected() != select && |
| | (!(en->getLayer() && en->getLayer()->isLocked()))){ |
| |
|
| | RS_Layer *l = en->getLayer(true); |
| |
|
| | if (l != nullptr && l->getName() == layerName){ |
| | en->setSelected(select); |
| | } |
| | } |
| | } |
| | m_graphicView->notifyChanged(); |
| | } |
| |
|