/////////////// Selection Routines /////////////////// // wf: this is never executed??? // needs a signal from Scene? hoverEvent? Scene does not emit signal for "preselect" void MDIViewPage::preSelectionChanged(const QPoint &pos) { QObject *obj = QObject::sender(); if(!obj) return; auto view( dynamic_cast<QGIView *>(obj) ); if(!view) return; QGraphicsItem* parent = view->parentItem(); if(!parent) return; TechDraw::DrawView *viewObj = view->getViewObject(); std::stringstream ss; QGIFace *face = dynamic_cast<QGIFace *>(obj); QGIEdge *edge = dynamic_cast<QGIEdge *>(obj); QGIVertex *vert = dynamic_cast<QGIVertex *>(obj); if(edge) { ss << "Edge" << edge->getProjIndex(); //bool accepted = static_cast<void> (Gui::Selection().setPreselect(viewObj->getDocument()->getName() ,viewObj->getNameInDocument() ,ss.str().c_str() ,pos.x() ,pos.y() ,0)); } else if(vert) { ss << "Vertex" << vert->getProjIndex(); //bool accepted = static_cast<void> (Gui::Selection().setPreselect(viewObj->getDocument()->getName() ,viewObj->getNameInDocument() ,ss.str().c_str() ,pos.x() ,pos.y() ,0)); } else if(face) { ss << "Face" << face->getProjIndex(); //TODO: SectionFaces have ProjIndex = -1. (but aren't selectable?) Problem? //bool accepted = static_cast<void> (Gui::Selection().setPreselect(viewObj->getDocument()->getName() ,viewObj->getNameInDocument() ,ss.str().c_str() ,pos.x() ,pos.y() ,0)); } else { ss << ""; Gui::Selection().setPreselect(viewObj->getDocument()->getName() ,viewObj->getNameInDocument() ,ss.str().c_str() ,pos.x() ,pos.y() ,0); } }
void QGIViewPart::toggleCosmeticLines(bool state) { QList<QGraphicsItem*> items = childItems(); for(QList<QGraphicsItem*>::iterator it = items.begin(); it != items.end(); it++) { QGIEdge *edge = dynamic_cast<QGIEdge *>(*it); if(edge) { edge->setCosmetic(state); } } }
void QGIViewPart::updateView(bool update) { if (getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { return; } QGIView::updateView(update); TechDraw::DrawViewPart *viewPart = dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()); if (update || viewPart->isTouched() || viewPart->Source.isTouched() || viewPart->Direction.isTouched() || viewPart->XAxisDirection.isTouched() || viewPart->Tolerance.isTouched() || viewPart->Scale.isTouched() || viewPart->ShowHiddenLines.isTouched() || viewPart->ShowSmoothLines.isTouched() || viewPart->ShowSeamLines.isTouched() ) { // Remove all existing graphical representations (QGIxxxx) otherwise BRect only grows, never shrinks? // is this where selection messes up? prepareGeometryChange(); QList<QGraphicsItem*> items = childItems(); for(QList<QGraphicsItem*>::iterator it = items.begin(); it != items.end(); ++it) { if (dynamic_cast<QGIEdge *> (*it) || dynamic_cast<QGIFace *>(*it) || dynamic_cast<QGIVertex *>(*it)) { removeFromGroup(*it); scene()->removeItem(*it); // We store these and delete till later to prevent rendering crash ISSUE deleteItems.append(*it); } } draw(); } else if (update || viewPart->LineWidth.isTouched() || viewPart->HiddenWidth.isTouched()) { QList<QGraphicsItem*> items = childItems(); for(QList<QGraphicsItem*>::iterator it = items.begin(); it != items.end(); ++it) { QGIEdge *edge = dynamic_cast<QGIEdge *>(*it); if(edge && edge->getHiddenEdge()) { edge->setStrokeWidth(viewPart->HiddenWidth.getValue() * lineScaleFactor); } else { edge->setStrokeWidth(viewPart->LineWidth.getValue() * lineScaleFactor); } } draw(); } else { QGIView::draw(); } }
void QGIViewPart::updateView(bool update) { auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) ); if( viewPart == nullptr ) { return; } QGIView::updateView(update); if (update || viewPart->isTouched() || viewPart->Source.isTouched() || viewPart->Direction.isTouched() || viewPart->Tolerance.isTouched() || viewPart->Scale.isTouched() || viewPart->HardHidden.isTouched() || viewPart->SmoothVisible.isTouched() || viewPart->SeamVisible.isTouched() || viewPart->IsoVisible.isTouched() || viewPart->SmoothHidden.isTouched() || viewPart->SeamHidden.isTouched() || viewPart->IsoHidden.isTouched() || viewPart->IsoCount.isTouched() ) { draw(); } else if (update || viewPart->LineWidth.isTouched() || viewPart->HiddenWidth.isTouched()) { QList<QGraphicsItem*> items = childItems(); for(QList<QGraphicsItem*>::iterator it = items.begin(); it != items.end(); ++it) { QGIEdge *edge = dynamic_cast<QGIEdge *>(*it); if(edge && edge->getHiddenEdge()) { edge->setWidth(viewPart->HiddenWidth.getValue() * lineScaleFactor); } else { edge->setWidth(viewPart->LineWidth.getValue() * lineScaleFactor); } } draw(); } else { QGIView::draw(); } }
void QGIViewPart::drawViewPart() { auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) ); if ( viewPart == nullptr ) { return; } float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor; float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor; float lineWidthIso = viewPart->IsoWidth.getValue() * lineScaleFactor; prepareGeometryChange(); removePrimitives(); //clean the slate removeDecorations(); #if MOD_TECHDRAW_HANDLE_FACES if (viewPart->handleFaces()) { // Draw Faces std::vector<TechDraw::DrawHatch*> hatchObjs = viewPart->getHatches(); const std::vector<TechDrawGeometry::Face *> &faceGeoms = viewPart->getFaceGeometry(); std::vector<TechDrawGeometry::Face *>::const_iterator fit = faceGeoms.begin(); for(int i = 0 ; fit != faceGeoms.end(); fit++, i++) { QGIFace* newFace = drawFace(*fit,i); TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs); if (fHatch) { if (!fHatch->HatchPattern.isEmpty()) { App::Color hColor = fHatch->HatchColor.getValue(); newFace->setHatchColor(hColor.asCSSString()); newFace->setHatch(fHatch->HatchPattern.getValue()); } } newFace->setDrawEdges(false); newFace->setZValue(ZVALUE::FACE); newFace->setPrettyNormal(); } } #endif //#if MOD_TECHDRAW_HANDLE_FACES // Draw Edges const std::vector<TechDrawGeometry::BaseGeom *> &geoms = viewPart->getEdgeGeometry(); std::vector<TechDrawGeometry::BaseGeom *>::const_iterator itEdge = geoms.begin(); QGIEdge* item; for(int i = 0 ; itEdge != geoms.end(); itEdge++, i++) { bool showEdge = false; if ((*itEdge)->visible) { if (((*itEdge)->classOfEdge == ecHARD) || ((*itEdge)->classOfEdge == ecOUTLINE) || (((*itEdge)->classOfEdge == ecSMOOTH) && viewPart->SmoothVisible.getValue()) || (((*itEdge)->classOfEdge == ecSEAM) && viewPart->SeamVisible.getValue()) || (((*itEdge)->classOfEdge == ecUVISO) && viewPart->IsoVisible.getValue())) { showEdge = true; } } else { if ( (((*itEdge)->classOfEdge == ecHARD) && (viewPart->HardHidden.getValue())) || (((*itEdge)->classOfEdge == ecOUTLINE) && (viewPart->HardHidden.getValue())) || (((*itEdge)->classOfEdge == ecSMOOTH) && (viewPart->SmoothHidden.getValue())) || (((*itEdge)->classOfEdge == ecSEAM) && (viewPart->SeamHidden.getValue())) || (((*itEdge)->classOfEdge == ecUVISO) && (viewPart->IsoHidden.getValue())) ) { showEdge = true; } } if (showEdge) { item = new QGIEdge(i); addToGroup(item); //item is at scene(0,0), not group(0,0) item->setPos(0.0,0.0); //now at group(0,0) item->setPath(drawPainterPath(*itEdge)); item->setWidth(lineWidth); item->setZValue(ZVALUE::EDGE); if(!(*itEdge)->visible) { item->setWidth(lineWidthHid); item->setHiddenEdge(true); item->setZValue(ZVALUE::HIDEDGE); } if ((*itEdge)->classOfEdge == ecUVISO) { item->setWidth(lineWidthIso); } item->setPrettyNormal(); //debug a path //QPainterPath edgePath=drawPainterPath(*itEdge); //std::stringstream edgeId; //edgeId << "QGIVP.edgePath" << i; //dumpPath(edgeId.str().c_str(),edgePath); } } // Draw Vertexs: const std::vector<TechDrawGeometry::Vertex *> &verts = viewPart->getVertexGeometry(); std::vector<TechDrawGeometry::Vertex *>::const_iterator vert = verts.begin(); bool showCenters = viewPart->ArcCenterMarks.getValue(); double cAdjust = viewPart->CenterScale.getValue(); for(int i = 0 ; vert != verts.end(); ++vert, i++) { if ((*vert)->isCenter) { if (showCenters) { QGICMark* cmItem = new QGICMark(i); addToGroup(cmItem); cmItem->setPos((*vert)->pnt.fX, (*vert)->pnt.fY); //this is in ViewPart coords cmItem->setThick(0.5 * lineWidth * lineScaleFactor); //need minimum? cmItem->setSize( cAdjust * lineWidth * vertexScaleFactor); cmItem->setZValue(ZVALUE::VERTEX); } } else { QGIVertex *item = new QGIVertex(i); addToGroup(item); item->setPos((*vert)->pnt.fX, (*vert)->pnt.fY); //this is in ViewPart coords item->setRadius(lineWidth * vertexScaleFactor); item->setZValue(ZVALUE::VERTEX); } } //draw section line if (viewPart->ShowSectionLine.getValue()) { auto refs = viewPart->getSectionRefs(); for (auto& r:refs) { drawSectionLine(r, true); } } //draw center lines drawCenterLines(true); }
//! update FC Selection from QGraphicsScene selection //trigged by m_view->scene() signal void MDIViewPage::selectionChanged() { if(isSelectionBlocked) { return; } QList<QGraphicsItem*> selection = m_view->scene()->selectedItems(); bool saveBlock = blockConnection(true); // avoid to be notified by itself blockSelection(true); Gui::Selection().clearSelection(); for (QList<QGraphicsItem*>::iterator it = selection.begin(); it != selection.end(); ++it) { QGIView *itemView = dynamic_cast<QGIView *>(*it); if(itemView == 0) { QGIEdge *edge = dynamic_cast<QGIEdge *>(*it); if(edge) { QGraphicsItem*parent = edge->parentItem(); if(!parent) continue; QGIView *viewItem = dynamic_cast<QGIView *>(parent); if(!viewItem) continue; TechDraw::DrawView *viewObj = viewItem->getViewObject(); std::stringstream ss; ss << "Edge" << edge->getProjIndex(); //bool accepted = static_cast<void> (Gui::Selection().addSelection(viewObj->getDocument()->getName(), viewObj->getNameInDocument(), ss.str().c_str())); showStatusMsg(viewObj->getDocument()->getName(), viewObj->getNameInDocument(), ss.str().c_str()); continue; } QGIVertex *vert = dynamic_cast<QGIVertex *>(*it); if(vert) { QGraphicsItem*parent = vert->parentItem(); if(!parent) continue; QGIView *viewItem = dynamic_cast<QGIView *>(parent); if(!viewItem) continue; TechDraw::DrawView *viewObj = viewItem->getViewObject(); std::stringstream ss; ss << "Vertex" << vert->getProjIndex(); //bool accepted = static_cast<void> (Gui::Selection().addSelection(viewObj->getDocument()->getName(), viewObj->getNameInDocument(), ss.str().c_str())); showStatusMsg(viewObj->getDocument()->getName(), viewObj->getNameInDocument(), ss.str().c_str()); continue; } QGIFace *face = dynamic_cast<QGIFace *>(*it); if(face) { QGraphicsItem*parent = face->parentItem(); if(!parent) continue; QGIView *viewItem = dynamic_cast<QGIView *>(parent); if(!viewItem) continue; TechDraw::DrawView *viewObj = viewItem->getViewObject(); std::stringstream ss; ss << "Face" << face->getProjIndex(); //bool accepted = static_cast<void> (Gui::Selection().addSelection(viewObj->getDocument()->getName(), viewObj->getNameInDocument(), ss.str().c_str())); showStatusMsg(viewObj->getDocument()->getName(), viewObj->getNameInDocument(), ss.str().c_str()); continue; } QGIDatumLabel *dimLabel = dynamic_cast<QGIDatumLabel*>(*it); if(dimLabel) { QGraphicsItem*dimParent = dimLabel->parentItem(); if(!dimParent) continue; QGIView *dimItem = dynamic_cast<QGIView *>(dimParent); if(!dimItem) continue; TechDraw::DrawView *dimObj = dimItem->getViewObject(); if (!dimObj) { continue; } const char* name = dimObj->getNameInDocument(); if (!name) { //can happen during undo/redo if Dim is selected??? //Base::Console().Log("INFO - MDIVP::selectionChanged - dimObj name is null!\n"); continue; } //bool accepted = static_cast<void> (Gui::Selection().addSelection(dimObj->getDocument()->getName(),dimObj->getNameInDocument())); } } else { TechDraw::DrawView *viewObj = itemView->getViewObject(); if (viewObj && !viewObj->isRemoving()) { std::string doc_name = viewObj->getDocument()->getName(); std::string obj_name = viewObj->getNameInDocument(); Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str()); showStatusMsg(doc_name.c_str(), obj_name.c_str(), ""); } } } blockConnection(saveBlock); blockSelection(false); } // end MDIViewPage::selectionChanged()
void QGIViewPart::drawViewPart() { if ( getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { return; } TechDraw::DrawViewPart *viewPart = dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()); float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor; float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor; prepareGeometryChange(); #if MOD_TECHDRAW_HANDLE_FACES // Draw Faces std::vector<TechDraw::DrawHatch*> hatchObjs = viewPart->getHatches(); const std::vector<TechDrawGeometry::Face *> &faceGeoms = viewPart->getFaceGeometry(); std::vector<TechDrawGeometry::Face *>::const_iterator fit = faceGeoms.begin(); for(int i = 0 ; fit != faceGeoms.end(); fit++, i++) { QGIFace* newFace = drawFace(*fit,i); TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs); if (fHatch) { if (!fHatch->HatchPattern.isEmpty()) { App::Color hColor = fHatch->HatchColor.getValue(); newFace->setHatchColor(hColor.asCSSString()); newFace->setHatch(fHatch->HatchPattern.getValue()); } } newFace->setZValue(ZVALUE::FACE); newFace->setPrettyNormal(); } #endif //#if MOD_TECHDRAW_HANDLE_FACES // Draw Edges const std::vector<TechDrawGeometry::BaseGeom *> &geoms = viewPart->getEdgeGeometry(); std::vector<TechDrawGeometry::BaseGeom *>::const_iterator itEdge = geoms.begin(); QGIEdge* item; for(int i = 0 ; itEdge != geoms.end(); itEdge++, i++) { bool showEdge = false; if ((*itEdge)->visible) { if (((*itEdge)->classOfEdge == ecHARD) || ((*itEdge)->classOfEdge == ecOUTLINE) || (((*itEdge)->classOfEdge == ecSMOOTH) && viewPart->ShowSmoothLines.getValue()) || (((*itEdge)->classOfEdge == ecSEAM) && viewPart->ShowSeamLines.getValue())) { showEdge = true; } } else { if (viewPart->ShowHiddenLines.getValue()) { showEdge = true; } } if (showEdge) { item = new QGIEdge(i); addToGroup(item); //item is at scene(0,0), not group(0,0) item->setPos(0.0,0.0); item->setPath(drawPainterPath(*itEdge)); item->setStrokeWidth(lineWidth); item->setZValue(ZVALUE::EDGE); if(!(*itEdge)->visible) { item->setStrokeWidth(lineWidthHid); item->setHiddenEdge(true); item->setZValue(ZVALUE::HIDEDGE); } item->setPrettyNormal(); //debug a path //QPainterPath edgePath=drawPainterPath(*itEdge); //std::stringstream edgeId; //edgeId << "QGIVP.edgePath" << i; //dumpPath(edgeId.str().c_str(),edgePath); } } // Draw Vertexs: const std::vector<TechDrawGeometry::Vertex *> &verts = viewPart->getVertexGeometry(); std::vector<TechDrawGeometry::Vertex *>::const_iterator vert = verts.begin(); for(int i = 0 ; vert != verts.end(); ++vert, i++) { QGIVertex *item = new QGIVertex(i); addToGroup(item); item->setPos((*vert)->pnt.fX, (*vert)->pnt.fY); //this is in ViewPart coords item->setRadius(lineWidth * vertexScaleFactor); item->setZValue(ZVALUE::VERTEX); } }