[TD] some style unification

automatically done by MSVC
This commit is contained in:
Uwe
2022-01-03 23:30:43 +01:00
parent 1999e7563c
commit 4b0767dec1
4 changed files with 252 additions and 240 deletions

View File

@@ -135,11 +135,11 @@ void CmdTechDrawPageDefault::activated(int iMsg)
if (tfi.isReadable()) {
Gui::WaitCursor wc;
openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str());
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str());
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawPage','%s')", PageName.c_str());
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')", TemplateName.c_str());
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",TemplateName.c_str(), templateFileName.toStdString().c_str());
doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str());
doCommand(Doc, "App.activeDocument().%s.Template = '%s'", TemplateName.c_str(), templateFileName.toStdString().c_str());
doCommand(Doc, "App.activeDocument().%s.Template = App.activeDocument().%s", PageName.c_str(), TemplateName.c_str());
updateActive();
commitCommand();
@@ -154,9 +154,10 @@ void CmdTechDrawPageDefault::activated(int iMsg)
dvp->show();
}
else {
Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(),TemplateName.c_str());
Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(), TemplateName.c_str());
}
} else {
}
else {
QMessageBox::critical(Gui::getMainWindow(),
QLatin1String("No template"),
QLatin1String("No default template found"));
@@ -208,17 +209,17 @@ void CmdTechDrawPageTemplate::activated(int iMsg)
if (tfi.isReadable()) {
Gui::WaitCursor wc;
openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str());
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawPage','%s')", PageName.c_str());
// Create the Template Object to attach to the page
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str());
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')", TemplateName.c_str());
//why is "Template" property set twice? -wf
// once to set DrawSVGTemplate.Template to OS template file name
templateFileName = Base::Tools::escapeEncodeFilename(templateFileName);
doCommand(Doc,"App.activeDocument().%s.Template = \"%s\"",TemplateName.c_str(), templateFileName.toUtf8().constData());
doCommand(Doc, "App.activeDocument().%s.Template = \"%s\"", TemplateName.c_str(), templateFileName.toUtf8().constData());
// once to set Page.Template to DrawSVGTemplate.Name
doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str());
doCommand(Doc, "App.activeDocument().%s.Template = App.activeDocument().%s", PageName.c_str(), TemplateName.c_str());
// consider renaming DrawSVGTemplate.Template property?
updateActive();
@@ -233,7 +234,7 @@ void CmdTechDrawPageTemplate::activated(int iMsg)
dvp->show();
}
else {
Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(),TemplateName.c_str());
Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(), TemplateName.c_str());
}
}
else {
@@ -281,7 +282,7 @@ void CmdTechDrawRedrawPage::activated(int iMsg)
bool CmdTechDrawRedrawPage::isActive(void)
{
bool havePage = DrawGuiUtil::needPage(this);
bool haveView = DrawGuiUtil::needView(this,false);
bool haveView = DrawGuiUtil::needView(this, false);
return (havePage && haveView);
}
@@ -327,19 +328,19 @@ void CmdTechDrawView::activated(int iMsg)
for (auto& sel: selection) {
bool is_linked = false;
auto obj = sel.getObject();
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) {
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) {
continue;
}
if ( obj->isDerivedFrom(App::LinkElement::getClassTypeId()) ||
obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) ||
obj->isDerivedFrom(App::Link::getClassTypeId()) ) {
if (obj->isDerivedFrom(App::LinkElement::getClassTypeId()) ||
obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) ||
obj->isDerivedFrom(App::Link::getClassTypeId()) ) {
is_linked = true;
}
// If parent of the obj is a link to another document, we possibly need to treat non-link obj as linked, too
// 1st, is obj in another document?
if (obj->getDocument() != this->getDocument()) {
std::set<App::DocumentObject *> parents = obj->getInListEx(true);
for (auto &parent: parents) {
std::set<App::DocumentObject*> parents = obj->getInListEx(true);
for (auto& parent : parents) {
// Only consider parents in the current document, i.e. possible links in this View's document
if (parent->getDocument() != this->getDocument()) {
continue;
@@ -360,11 +361,11 @@ void CmdTechDrawView::activated(int iMsg)
//not a Link and not null. assume to be drawable. Undrawables will be
// skipped later.
shapes.push_back(obj);
if(partObj != nullptr) {
if (partObj != nullptr) {
continue;
}
//don't know if this works for an XLink
for(auto& sub : sel.getSubNames()) {
for (auto& sub : sel.getSubNames()) {
if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
faceName = sub;
//
@@ -374,8 +375,8 @@ void CmdTechDrawView::activated(int iMsg)
}
}
if ( shapes.empty() &&
xShapes.empty() ) {
if (shapes.empty() &&
xShapes.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Shapes, Groups or Links in this selection"));
return;
@@ -386,39 +387,40 @@ void CmdTechDrawView::activated(int iMsg)
Gui::WaitCursor wc;
openCommand(QT_TRANSLATE_NOOP("Command", "Create view"));
std::string FeatName = getUniqueObjectName("View");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewPart','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewPart','%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str());
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart *>(docObj);
App::DocumentObject* docObj = getDocument()->getObject(FeatName.c_str());
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(docObj);
if (!dvp) {
throw Base::TypeError("CmdTechDrawView DVP not found\n");
}
dvp->Source.setValues(shapes);
dvp->XSource.setValues(xShapes);
if (faceName.size()) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partObj,faceName);
std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partObj, faceName);
projDir = dirs.first;
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), projDir.x,projDir.y,projDir.z);
doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), projDir.x, projDir.y, projDir.z);
//do something clever with dirs.second;
// dvp->setXDir(dirs.second);
doCommand(Doc,"App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z);
doCommand(Doc,"App.activeDocument().%s.recompute()", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
doCommand(Doc, "App.activeDocument().%s.recompute()", FeatName.c_str());
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
} else {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
}
else {
std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
projDir = dirs.first;
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), projDir.x,projDir.y,projDir.z);
doCommand(Doc,"App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z);
// dvp->setXDir(dirs.second);
doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), projDir.x, projDir.y, projDir.z);
doCommand(Doc, "App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
// dvp->setXDir(dirs.second);
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
doCommand(Doc,"App.activeDocument().%s.recompute()", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.recompute()", FeatName.c_str());
}
commitCommand();
}
@@ -538,7 +540,7 @@ void CmdTechDrawDetailView::activated(int iMsg)
return;
}
std::vector<App::DocumentObject*> baseObj = getSelection().
std::vector<App::DocumentObject*> baseObj = getSelection().
getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId());
if (baseObj.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
@@ -605,19 +607,19 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
for (auto& sel: selection) {
bool is_linked = false;
auto obj = sel.getObject();
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) {
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) {
continue;
}
if ( obj->isDerivedFrom(App::LinkElement::getClassTypeId()) ||
obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) ||
obj->isDerivedFrom(App::Link::getClassTypeId()) ) {
if (obj->isDerivedFrom(App::LinkElement::getClassTypeId()) ||
obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) ||
obj->isDerivedFrom(App::Link::getClassTypeId()) ) {
is_linked = true;
}
// If parent of the obj is a link to another document, we possibly need to treat non-link obj as linked, too
// 1st, is obj in another document?
if (obj->getDocument() != this->getDocument()) {
std::set<App::DocumentObject *> parents = obj->getInListEx(true);
for (auto &parent: parents) {
std::set<App::DocumentObject*> parents = obj->getInListEx(true);
for (auto& parent : parents) {
// Only consider parents in the current document, i.e. possible links in this View's document
if (parent->getDocument() != this->getDocument()) {
continue;
@@ -638,10 +640,10 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
//not a Link and not null. assume to be drawable. Undrawables will be
// skipped later.
shapes.push_back(obj);
if(partObj != nullptr) {
if (partObj != nullptr) {
continue;
}
for(auto& sub : sel.getSubNames()) {
for (auto& sub : sel.getSubNames()) {
if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
faceName = sub;
partObj = obj;
@@ -649,8 +651,8 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
}
}
}
if ( shapes.empty() &&
xShapes.empty() ) {
if (shapes.empty() &&
xShapes.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Shapes, Groups or Links in this selection"));
return;
@@ -662,45 +664,46 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
openCommand(QT_TRANSLATE_NOOP("Command", "Create Projection Group"));
std::string multiViewName = getUniqueObjectName("ProjGroup");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawProjGroup','%s')",
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawProjGroup','%s')",
multiViewName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",
PageName.c_str(),multiViewName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)",
PageName.c_str(), multiViewName.c_str());
App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str());
auto multiView( static_cast<TechDraw::DrawProjGroup *>(docObj) );
App::DocumentObject* docObj = getDocument()->getObject(multiViewName.c_str());
auto multiView(static_cast<TechDraw::DrawProjGroup*>(docObj));
multiView->Source.setValues(shapes);
multiView->XSource.setValues(xShapes);
doCommand(Doc,"App.activeDocument().%s.addProjection('Front')",multiViewName.c_str());
doCommand(Doc, "App.activeDocument().%s.addProjection('Front')", multiViewName.c_str());
if (faceName.size()) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partObj,faceName);
std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partObj, faceName);
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
doCommand(Doc,"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z);
doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z);
doCommand(Doc,"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z);
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
} else {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
doCommand(Doc,"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z);
doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z);
doCommand(Doc,"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z);
doCommand(Doc, "App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
doCommand(Doc, "App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
doCommand(Doc, "App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
}
doCommand(Doc,"App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str());
else {
std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
doCommand(Doc, "App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
doCommand(Doc, "App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
doCommand(Doc, "App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
}
doCommand(Doc, "App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str());
commitCommand();
updateActive();
// create the rest of the desired views
Gui::Control().showDialog(new TaskDlgProjGroup(multiView,true));
Gui::Control().showDialog(new TaskDlgProjGroup(multiView, true));
}
bool CmdTechDrawProjectionGroup::isActive(void)
@@ -710,7 +713,7 @@ bool CmdTechDrawProjectionGroup::isActive(void)
if (havePage) {
taskInProgress = Gui::Control().activeDialog();
}
return (havePage && !taskInProgress);
return (havePage && !taskInProgress);
}
//===========================================================================
@@ -781,14 +784,14 @@ bool _checkSelectionBalloon(Gui::Command* cmd, unsigned maxObjs) {
}
const std::vector<std::string> SubNames = selection[0].getSubNames();
if (SubNames.size() > maxObjs){
if (SubNames.size() > maxObjs) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
QObject::tr("Too many objects selected"));
return false;
}
std::vector<App::DocumentObject*> pages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
if (pages.empty()){
if (pages.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
QObject::tr("Create a page first."));
return false;
@@ -798,17 +801,17 @@ bool _checkSelectionBalloon(Gui::Command* cmd, unsigned maxObjs) {
bool _checkDrawViewPartBalloon(Gui::Command* cmd) {
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
if( !objFeat ) {
QMessageBox::warning( Gui::getMainWindow(),
QObject::tr("Incorrect selection"),
QObject::tr("No View of a Part in selection.") );
auto objFeat(dynamic_cast<TechDraw::DrawViewPart*>(selection[0].getObject()));
if (!objFeat) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Incorrect selection"),
QObject::tr("No View of a Part in selection.") );
return false;
}
return true;
}
bool _checkDirectPlacement(const QGIViewPart *viewPart, const std::vector<std::string> &subNames, QPointF &placement)
bool _checkDirectPlacement(const QGIViewPart* viewPart, const std::vector<std::string>& subNames, QPointF& placement)
{
// Let's see, if we can help speed up the placement of the balloon:
// As of now we support:
@@ -825,7 +828,7 @@ bool _checkDirectPlacement(const QGIViewPart *viewPart, const std::vector<std::s
std::string geoType = TechDraw::DrawUtil::getGeomTypeFromName(subNames[0]);
if (geoType == "Vertex") {
int index = TechDraw::DrawUtil::getIndexFromName(subNames[0]);
TechDraw::VertexPtr vertex = static_cast<DrawViewPart *>(viewPart->getViewObject())->getProjVertexByIndex(index);
TechDraw::VertexPtr vertex = static_cast<DrawViewPart*>(viewPart->getViewObject())->getProjVertexByIndex(index);
if (vertex) {
placement = viewPart->mapToScene(Rez::guiX(vertex->x()), Rez::guiX(vertex->y()));
return true;
@@ -833,7 +836,7 @@ bool _checkDirectPlacement(const QGIViewPart *viewPart, const std::vector<std::s
}
else if (geoType == "Edge") {
int index = TechDraw::DrawUtil::getIndexFromName(subNames[0]);
TechDraw::BaseGeom *geo = static_cast<DrawViewPart *>(viewPart->getViewObject())->getGeomByIndex(index);
TechDraw::BaseGeom* geo = static_cast<DrawViewPart*>(viewPart->getViewObject())->getGeomByIndex(index);
if (geo) {
Base::Vector3d midPoint(Rez::guiX(geo->getMidPoint()));
placement = viewPart->mapToScene(midPoint.x, midPoint.y);
@@ -861,7 +864,7 @@ CmdTechDrawBalloon::CmdTechDrawBalloon()
void CmdTechDrawBalloon::activated(int iMsg)
{
Q_UNUSED(iMsg);
bool result = _checkSelectionBalloon(this,1);
bool result = _checkSelectionBalloon(this, 1);
if (!result)
return;
result = _checkDrawViewPartBalloon(this);
@@ -870,8 +873,8 @@ void CmdTechDrawBalloon::activated(int iMsg)
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
if( objFeat == nullptr ) {
auto objFeat(dynamic_cast<TechDraw::DrawViewPart*>(selection[0].getObject()));
if (objFeat == nullptr) {
return;
}
@@ -880,16 +883,16 @@ void CmdTechDrawBalloon::activated(int iMsg)
page->balloonParent = objFeat;
Gui::Document *guiDoc = Gui::Application::Instance->getDocument(page->getDocument());
ViewProviderPage *pageVP = dynamic_cast<ViewProviderPage *>(guiDoc->getViewProvider(page));
ViewProviderViewPart *partVP = dynamic_cast<ViewProviderViewPart *>(guiDoc->getViewProvider(objFeat));
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(page->getDocument());
ViewProviderPage* pageVP = dynamic_cast<ViewProviderPage*>(guiDoc->getViewProvider(page));
ViewProviderViewPart* partVP = dynamic_cast<ViewProviderViewPart*>(guiDoc->getViewProvider(objFeat));
if (pageVP && partVP) {
QGVPage *viewPage = pageVP->getGraphicsView();
QGVPage* viewPage = pageVP->getGraphicsView();
if (viewPage) {
viewPage->startBalloonPlacing();
QGIViewPart *viewPart = dynamic_cast<QGIViewPart *>(partVP->getQView());
QGIViewPart* viewPart = dynamic_cast<QGIViewPart*>(partVP->getQView());
QPointF placement;
if (viewPart && _checkDirectPlacement(viewPart, selection[0].getSubNames(), placement)) {
viewPage->createBalloon(placement, objFeat);
@@ -934,8 +937,8 @@ void CmdTechDrawClipGroup::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Clip");
openCommand(QT_TRANSLATE_NOOP("Command", "Create Clip"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewClip','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewClip','%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
updateActive();
commitCommand();
}
@@ -965,20 +968,21 @@ CmdTechDrawClipGroupAdd::CmdTechDrawClipGroupAdd()
void CmdTechDrawClipGroupAdd::activated(int iMsg)
{
Q_UNUSED(iMsg);
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() != 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select one Clip group and one View."));
return;
}
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() != 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select one Clip group and one View."));
return;
}
TechDraw::DrawViewClip* clip = 0;
TechDraw::DrawView* view = 0;
std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
for (; itSel != selection.end(); itSel++) {
for (; itSel != selection.end(); itSel++) {
if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) {
clip = static_cast<TechDraw::DrawViewClip*>((*itSel).getObject());
} else if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
}
else if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
view = static_cast<TechDraw::DrawView*>((*itSel).getObject());
}
}
@@ -1007,9 +1011,9 @@ void CmdTechDrawClipGroupAdd::activated(int iMsg)
std::string ViewName = view->getNameInDocument();
openCommand(QT_TRANSLATE_NOOP("Command", "ClipGroupAdd"));
doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = False",ViewName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",ClipName.c_str(),ViewName.c_str());
doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = True",ViewName.c_str());
doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = False", ViewName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", ClipName.c_str(), ViewName.c_str());
doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = True", ViewName.c_str());
updateActive();
commitCommand();
}
@@ -1019,7 +1023,7 @@ bool CmdTechDrawClipGroupAdd::isActive(void)
bool havePage = DrawGuiUtil::needPage(this);
bool haveClip = false;
if (havePage) {
auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() );
auto drawClipType(TechDraw::DrawViewClip::getClassTypeId());
auto selClips = getDocument()->getObjectsOfType(drawClipType);
if (!selClips.empty()) {
haveClip = true;
@@ -1048,20 +1052,20 @@ CmdTechDrawClipGroupRemove::CmdTechDrawClipGroupRemove()
void CmdTechDrawClipGroupRemove::activated(int iMsg)
{
Q_UNUSED(iMsg);
auto dObj( getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()) );
auto dObj(getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()));
if (dObj.empty()) {
QMessageBox::warning( Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("Select exactly one View to remove from Group.") );
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("Select exactly one View to remove from Group.") );
return;
}
auto view( static_cast<TechDraw::DrawView*>(dObj.front()) );
auto view(static_cast<TechDraw::DrawView*>(dObj.front()));
TechDraw::DrawPage* page = view->findParentPage();
const std::vector<App::DocumentObject*> pViews = page->Views.getValues();
TechDraw::DrawViewClip *clip(nullptr);
for (auto &v : pViews) {
TechDraw::DrawViewClip* clip(nullptr);
for (auto& v : pViews) {
clip = dynamic_cast<TechDraw::DrawViewClip*>(v);
if (clip && clip->isViewInClip(view)) {
break;
@@ -1070,9 +1074,9 @@ void CmdTechDrawClipGroupRemove::activated(int iMsg)
}
if (!clip) {
QMessageBox::warning( Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("View does not belong to a Clip") );
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("View does not belong to a Clip") );
return;
}
@@ -1080,9 +1084,9 @@ void CmdTechDrawClipGroupRemove::activated(int iMsg)
std::string ViewName = view->getNameInDocument();
openCommand(QT_TRANSLATE_NOOP("Command", "ClipGroupRemove"));
doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = False",ViewName.c_str());
doCommand(Doc,"App.activeDocument().%s.removeView(App.activeDocument().%s)",ClipName.c_str(),ViewName.c_str());
doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = True",ViewName.c_str());
doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = False", ViewName.c_str());
doCommand(Doc, "App.activeDocument().%s.removeView(App.activeDocument().%s)", ClipName.c_str(), ViewName.c_str());
doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = True", ViewName.c_str());
updateActive();
commitCommand();
}
@@ -1092,7 +1096,7 @@ bool CmdTechDrawClipGroupRemove::isActive(void)
bool havePage = DrawGuiUtil::needPage(this);
bool haveClip = false;
if (havePage) {
auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() );
auto drawClipType(TechDraw::DrawViewClip::getClassTypeId());
auto selClips = getDocument()->getObjectsOfType(drawClipType);
if (!selClips.empty()) {
haveClip = true;
@@ -1130,7 +1134,7 @@ void CmdTechDrawSymbol::activated(int iMsg)
std::string PageName = page->getNameInDocument();
// Reading an image
QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
QObject::tr("Choose an SVG file to open"), QString(),
QString::fromLatin1("%1 (*.svg *.svgz);;%2 (*.*)").
arg(QObject::tr("Scalable Vector Graphic")).
@@ -1141,12 +1145,12 @@ void CmdTechDrawSymbol::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Symbol");
filename = Base::Tools::escapeEncodeFilename(filename);
openCommand(QT_TRANSLATE_NOOP("Command", "Create Symbol"));
doCommand(Doc,"f = open(\"%s\",'r')",(const char*)filename.toUtf8());
doCommand(Doc,"svg = f.read()");
doCommand(Doc,"f.close()");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSymbol','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Symbol = svg",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
doCommand(Doc, "f = open(\"%s\",'r')", (const char*)filename.toUtf8());
doCommand(Doc, "svg = f.read()");
doCommand(Doc, "f.close()");
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSymbol','%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Symbol = svg", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
updateActive();
commitCommand();
}
@@ -1193,26 +1197,26 @@ void CmdTechDrawDraftView::activated(int iMsg)
return;
}
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
int draftItemsFound = 0;
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it) {
if (DrawGuiUtil::isDraftObject((*it))) {
if (DrawGuiUtil::isDraftObject((*it))) {
draftItemsFound++;
std::string FeatName = getUniqueObjectName("DraftView");
std::string SourceName = (*it)->getNameInDocument();
openCommand(QT_TRANSLATE_NOOP("Command", "Create DraftView"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDraft','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",
FeatName.c_str(),SourceName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",
PageName.c_str(),FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewDraft','%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s",
FeatName.c_str(), SourceName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)",
PageName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
FeatName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
updateActive();
commitCommand();
}
}
if (draftItemsFound == 0) {
if (draftItemsFound == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("There were no DraftWB objects in the selection."));
}
@@ -1247,21 +1251,21 @@ void CmdTechDrawArchView::activated(int iMsg)
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
if (!page) {
return;
}
}
std::string PageName = page->getNameInDocument();
const std::vector<App::DocumentObject*> objects = getSelection().
getObjectsOfType(App::DocumentObject::getClassTypeId());
const std::vector<App::DocumentObject*> objects = getSelection().
getObjectsOfType(App::DocumentObject::getClassTypeId());
App::DocumentObject* archObject = nullptr;
int archCount = 0;
for (auto& obj : objects) {
if (DrawGuiUtil::isArchSection(obj) ) {
if (DrawGuiUtil::isArchSection(obj)) {
archCount++;
archObject = obj;
}
}
if ( archCount > 1 ) {
if (archCount > 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Please select only 1 Arch Section."));
return;
@@ -1276,9 +1280,9 @@ void CmdTechDrawArchView::activated(int iMsg)
std::string FeatName = getUniqueObjectName("ArchView");
std::string SourceName = archObject->getNameInDocument();
openCommand(QT_TRANSLATE_NOOP("Command", "Create ArchView"));
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewArch','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SourceName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewArch','%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(), SourceName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
updateActive();
commitCommand();
}
@@ -1325,9 +1329,9 @@ void CmdTechDrawSpreadsheetView::activated(int iMsg)
openCommand(QT_TRANSLATE_NOOP("Command", "Create spreadsheet view"));
std::string FeatName = getUniqueObjectName("Sheet");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SpreadName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet','%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(), SpreadName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
updateActive();
commitCommand();
}
@@ -1338,7 +1342,7 @@ bool CmdTechDrawSpreadsheetView::isActive(void)
bool havePage = DrawGuiUtil::needPage(this);
bool haveSheet = false;
if (havePage) {
auto spreadSheetType( Spreadsheet::Sheet::getClassTypeId() );
auto spreadSheetType(Spreadsheet::Sheet::getClassTypeId());
auto selSheets = getDocument()->getObjectsOfType(spreadSheetType);
if (!selSheets.empty()) {
haveSheet = true;
@@ -1378,9 +1382,10 @@ void CmdTechDrawExportPageSVG::activated(int iMsg)
Gui::ViewProvider* vp = activeGui->getViewProvider(page);
ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
if (dvp && dvp->getMDIViewPage()) {
if (dvp && dvp->getMDIViewPage()) {
dvp->getMDIViewPage()->saveSVG();
} else {
}
else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Drawing View"),
QObject::tr("Open Drawing View before attempting export to SVG."));
return;
@@ -1418,15 +1423,16 @@ void CmdTechDrawExportPageDXF::activated(int iMsg)
}
std::vector<App::DocumentObject*> views = page->Views.getValues();
for (auto& v: views) {
for (auto& v : views) {
if (v->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId())) {
QMessageBox::StandardButton rc =
QMessageBox::question(Gui::getMainWindow(), QObject::tr("Can not export selection"),
QObject::tr("Page contains DrawViewArch which will not be exported. Continue?"),
QMessageBox::StandardButtons(QMessageBox::Yes| QMessageBox::No));
QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No));
if (rc == QMessageBox::No) {
return;
} else {
}
else {
break;
}
}
@@ -1445,9 +1451,9 @@ void CmdTechDrawExportPageDXF::activated(int iMsg)
std::string PageName = page->getNameInDocument();
openCommand(QT_TRANSLATE_NOOP("Command", "Save page to dxf"));
doCommand(Doc,"import TechDraw");
doCommand(Doc, "import TechDraw");
fileName = Base::Tools::escapeEncodeFilename(fileName);
doCommand(Doc,"TechDraw.writeDXFPage(App.activeDocument().%s,u\"%s\")",PageName.c_str(),(const char*)fileName.toUtf8());
doCommand(Doc, "TechDraw.writeDXFPage(App.activeDocument().%s,u\"%s\")", PageName.c_str(), (const char*)fileName.toUtf8());
commitCommand();
}
@@ -1459,7 +1465,7 @@ bool CmdTechDrawExportPageDXF::isActive(void)
void CreateTechDrawCommands(void)
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
rcCmdMgr.addCommand(new CmdTechDrawPageDefault());
rcCmdMgr.addCommand(new CmdTechDrawPageTemplate());

View File

@@ -33,7 +33,7 @@
#include "DlgPageChooser.h"
#include "ui_DlgPageChooser.h"
FC_LOG_LEVEL_INIT("Gui",true,true)
FC_LOG_LEVEL_INIT("Gui", true, true)
using namespace TechDrawGui;
@@ -47,7 +47,7 @@ DlgPageChooser::DlgPageChooser(
{
ui->setupUi(this);
ui->lwPages->setSortingEnabled(true);
fillList(labels, names);
connect(ui->bbButtons, SIGNAL(accepted()), this, SLOT(accept()));
@@ -71,7 +71,7 @@ void DlgPageChooser::fillList(std::vector<std::string> labels, std::vector<std::
QString qText;
int labelCount = labels.size();
int i = 0;
for(; i < labelCount; i++) {
for (; i < labelCount; i++) {
qLabel = Base::Tools::fromStdString(labels[i]);
qName = Base::Tools::fromStdString(names[i]);
qText = QString::fromUtf8("%1 (%2)").arg(qLabel).arg(qName);
@@ -80,7 +80,7 @@ void DlgPageChooser::fillList(std::vector<std::string> labels, std::vector<std::
}
}
std::string DlgPageChooser::getSelection() const
std::string DlgPageChooser::getSelection() const
{
std::string result;
QList<QListWidgetItem*> sels = ui->lwPages->selectedItems();

View File

@@ -118,7 +118,8 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd)
//no page in document
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"),
QObject::tr("No Drawing Pages in document."));
} else if (selPages.size() > 1) {
}
else if (selPages.size() > 1) {
//multiple pages in document, but none selected
//use active page if there is one
Gui::MainWindow* w = Gui::getMainWindow();
@@ -128,40 +129,44 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd)
QString windowTitle = mvp->windowTitle();
QGVPage* qp = mvp->getQGVPage();
page = qp->getDrawPage();
} else {
}
else {
// no active page
for(auto obj: selPages) {
for (auto obj : selPages) {
std::string name = obj->getNameInDocument();
names.push_back(name);
std::string label = obj->Label.getValue();
labels.push_back(label);
}
DlgPageChooser dlg(labels, names, Gui::getMainWindow());
if(dlg.exec()==QDialog::Accepted) {
if (dlg.exec() == QDialog::Accepted) {
std::string selName = dlg.getSelection();
App::Document* doc = cmd->getDocument();
App::Document* doc = cmd->getDocument();
page = static_cast<TechDraw::DrawPage*>(doc->getObject(selName.c_str()));
}
}
} else {
}
else {
//only 1 page in document - use it
page = static_cast<TechDraw::DrawPage*>(selPages.front());
}
} else if (selPages.size() > 1) {
}
else if (selPages.size() > 1) {
//multiple pages in selection
for(auto obj: selPages) {
for (auto obj : selPages) {
std::string name = obj->getNameInDocument();
names.push_back(name);
std::string label = obj->Label.getValue();
labels.push_back(label);
}
DlgPageChooser dlg(labels, names, Gui::getMainWindow());
if(dlg.exec()==QDialog::Accepted) {
if (dlg.exec() == QDialog::Accepted) {
std::string selName = dlg.getSelection();
App::Document* doc = cmd->getDocument();
App::Document* doc = cmd->getDocument();
page = static_cast<TechDraw::DrawPage*>(doc->getObject(selName.c_str()));
}
} else {
}
else {
//exactly 1 page in selection, use it
page = static_cast<TechDraw::DrawPage*>(selPages.front());
}
@@ -171,7 +176,7 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd)
bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj)
{
bool result = false;
bool result = false;
App::PropertyPythonObject* proxy = dynamic_cast<App::PropertyPythonObject*>(obj->getPropertyByName("Proxy"));
if (proxy != nullptr) {
@@ -183,10 +188,11 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj)
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
ss << (std::string)mod;
if (ss.str().find("Draft") != std::string::npos) {
result = true;
} else if (ss.str().find("draft") != std::string::npos) {
}
else if (ss.str().find("draft") != std::string::npos) {
result = true;
}
}
@@ -202,7 +208,7 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj)
bool DrawGuiUtil::isArchObject(App::DocumentObject* obj)
{
bool result = false;
bool result = false;
App::PropertyPythonObject* proxy = dynamic_cast<App::PropertyPythonObject*>(obj->getPropertyByName("Proxy"));
if (proxy != nullptr) {
@@ -214,7 +220,7 @@ bool DrawGuiUtil::isArchObject(App::DocumentObject* obj)
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
ss << (std::string)mod;
//does this have to be an ArchSection, or can it be any Arch object?
if (ss.str().find("Arch") != std::string::npos) {
result = true;
@@ -244,7 +250,7 @@ bool DrawGuiUtil::isArchSection(App::DocumentObject* obj)
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
ss << (std::string)mod;
//does this have to be an ArchSection, or can it be other Arch objects?
if (ss.str().find("ArchSectionPlane") != std::string::npos) {
result = true;
@@ -265,7 +271,7 @@ bool DrawGuiUtil::needPage(Gui::Command* cmd)
//need a Document and a Page
bool active = false;
if (cmd->hasActiveDocument()) {
auto drawPageType( TechDraw::DrawPage::getClassTypeId() );
auto drawPageType(TechDraw::DrawPage::getClassTypeId());
auto selPages = cmd->getDocument()->getObjectsOfType(drawPageType);
if (!selPages.empty()) {
active = true;
@@ -279,13 +285,14 @@ bool DrawGuiUtil::needView(Gui::Command* cmd, bool partOnly)
bool haveView = false;
if (cmd->hasActiveDocument()) {
if (partOnly) {
auto drawPartType (TechDraw::DrawViewPart::getClassTypeId());
auto drawPartType(TechDraw::DrawViewPart::getClassTypeId());
auto selParts = cmd->getDocument()->getObjectsOfType(drawPartType);
if (!selParts.empty()) {
haveView = true;
}
} else {
auto drawViewType (TechDraw::DrawView::getClassTypeId());
}
else {
auto drawViewType(TechDraw::DrawView::getClassTypeId());
auto selParts = cmd->getDocument()->getObjectsOfType(drawViewType);
if (!selParts.empty()) {
haveView = true;
@@ -297,32 +304,32 @@ bool DrawGuiUtil::needView(Gui::Command* cmd, bool partOnly)
void DrawGuiUtil::dumpRectF(const char* text, const QRectF& r)
{
Base::Console().Message("DUMP - dumpRectF - %s\n",text);
Base::Console().Message("DUMP - dumpRectF - %s\n", text);
double left = r.left();
double right = r.right();
double top = r.top();
double bottom = r.bottom();
Base::Console().Message("Extents: L: %.3f, R: %.3f, T: %.3f, B: %.3f\n",left,right,top,bottom);
Base::Console().Message("Size: W: %.3f H: %.3f\n",r.width(),r.height());
Base::Console().Message("Centre: (%.3f, %.3f)\n",r.center().x(),r.center().y());
Base::Console().Message("Extents: L: %.3f, R: %.3f, T: %.3f, B: %.3f\n", left, right, top, bottom);
Base::Console().Message("Size: W: %.3f H: %.3f\n", r.width(), r.height());
Base::Console().Message("Centre: (%.3f, %.3f)\n", r.center().x(), r.center().y());
}
void DrawGuiUtil::dumpPointF(const char* text, const QPointF& p)
{
Base::Console().Message("DUMP - dumpPointF - %s\n",text);
Base::Console().Message("Point: (%.3f, %.3f)\n",p.x(),p.y());
Base::Console().Message("DUMP - dumpPointF - %s\n", text);
Base::Console().Message("Point: (%.3f, %.3f)\n", p.x(), p.y());
}
std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::get3DDirAndRot()
std::pair<Base::Vector3d, Base::Vector3d> DrawGuiUtil::get3DDirAndRot()
{
std::pair<Base::Vector3d,Base::Vector3d> result;
Base::Vector3d viewDir(0.0,-1.0,0.0); //default to front
Base::Vector3d viewUp(0.0,0.0,1.0); //default to top
Base::Vector3d viewRight(1.0,0.0,0.0); //default to right
std::pair<Base::Vector3d, Base::Vector3d> result;
Base::Vector3d viewDir(0.0, -1.0, 0.0); //default to front
Base::Vector3d viewUp(0.0, 0.0, 1.0); //default to top
Base::Vector3d viewRight(1.0, 0.0, 0.0); //default to right
std::list<Gui::MDIView*> mdis = Gui::Application::Instance->activeDocument()->getMDIViews();
Gui::View3DInventor *view;
Gui::View3DInventorViewer *viewer = nullptr;
for (auto& m: mdis) { //find the 3D viewer
Gui::View3DInventor* view;
Gui::View3DInventorViewer* viewer = nullptr;
for (auto& m : mdis) { //find the 3D viewer
view = dynamic_cast<Gui::View3DInventor*>(m);
if (view) {
viewer = view->getViewer();
@@ -331,7 +338,7 @@ std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::get3DDirAndRot()
}
if (!viewer) {
Base::Console().Log("LOG - DrawGuiUtil could not find a 3D viewer\n");
return std::make_pair( viewDir, viewRight);
return std::make_pair(viewDir, viewRight);
}
SbVec3f dvec = viewer->getViewDirection();
@@ -341,45 +348,45 @@ std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::get3DDirAndRot()
viewDir = viewDir * (-1.0); // Inventor dir is opposite TD projection dir
viewUp = Base::Vector3d(upvec[0],upvec[1],upvec[2]);
// Base::Vector3d dirXup = viewDir.Cross(viewUp);
// Base::Vector3d dirXup = viewDir.Cross(viewUp);
Base::Vector3d right = viewUp.Cross(viewDir);
result = std::make_pair(viewDir,right);
result = std::make_pair(viewDir, right);
return result;
}
std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::getProjDirFromFace(App::DocumentObject* obj, std::string faceName)
std::pair<Base::Vector3d, Base::Vector3d> DrawGuiUtil::getProjDirFromFace(App::DocumentObject* obj, std::string faceName)
{
std::pair<Base::Vector3d,Base::Vector3d> d3Dirs = get3DDirAndRot();
std::pair<Base::Vector3d, Base::Vector3d> d3Dirs = get3DDirAndRot();
Base::Vector3d d3Up = (d3Dirs.first).Cross(d3Dirs.second);
std::pair<Base::Vector3d,Base::Vector3d> dirs;
dirs.first = Base::Vector3d(0.0,0.0,1.0); //set a default
dirs.second = Base::Vector3d(1.0,0.0,0.0);
std::pair<Base::Vector3d, Base::Vector3d> dirs;
dirs.first = Base::Vector3d(0.0, 0.0, 1.0); //set a default
dirs.second = Base::Vector3d(1.0, 0.0, 0.0);
Base::Vector3d projDir, rotVec;
projDir = d3Dirs.first;
rotVec = d3Dirs.second;
auto ts = Part::Feature::getShape(obj,faceName.c_str(),true);
if(ts.IsNull() || ts.ShapeType()!=TopAbs_FACE) {
Base::Console().Warning("getProjDirFromFace(%s) is not a Face\n",faceName.c_str());
auto ts = Part::Feature::getShape(obj, faceName.c_str(), true);
if (ts.IsNull() || ts.ShapeType() != TopAbs_FACE) {
Base::Console().Warning("getProjDirFromFace(%s) is not a Face\n", faceName.c_str());
return dirs;
}
const TopoDS_Face& face = TopoDS::Face(ts);
TopAbs_Orientation orient = face.Orientation();
BRepAdaptor_Surface adapt(face);
double u1 = adapt.FirstUParameter();
double u2 = adapt.LastUParameter();
double v1 = adapt.FirstVParameter();
double v2 = adapt.LastVParameter();
double uMid = (u1+u2)/2.0;
double vMid = (v1+v2)/2.0;
double uMid = (u1 + u2) / 2.0;
double vMid = (v1 + v2) / 2.0;
BRepLProp_SLProps props(adapt,uMid,vMid,2,Precision::Confusion());
BRepLProp_SLProps props(adapt, uMid, vMid, 2, Precision::Confusion());
if (props.IsNormalDefined()) {
gp_Dir vec = props.Normal();
projDir = Base::Vector3d(vec.X(),vec.Y(),vec.Z());
projDir = Base::Vector3d(vec.X(), vec.Y(), vec.Z());
rotVec = projDir.Cross(d3Up);
if (orient != TopAbs_FORWARD) {
projDir = projDir * (-1.0);
@@ -389,8 +396,6 @@ std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::getProjDirFromFace(App::Do
Base::Console().Log("Selected Face has no normal at midpoint\n");
}
dirs = std::make_pair(projDir,rotVec);
dirs = std::make_pair(projDir, rotVec);
return dirs;
}

View File

@@ -86,10 +86,10 @@ TaskCosVertex::TaskCosVertex(TechDraw::DrawViewPart* baseFeat,
m_btnOK(nullptr),
m_btnCancel(nullptr),
m_pbTrackerState(TRACKERPICK),
m_savePoint(QPointF(0.0,0.0))
m_savePoint(QPointF(0.0, 0.0))
{
if ( (m_basePage == nullptr) ||
(m_baseFeat == nullptr) ) {
if ((m_basePage == nullptr) ||
(m_baseFeat == nullptr)) {
//should be caught in CMD caller
Base::Console().Error("TaskCosVertex - bad parameters. Can not proceed.\n");
return;
@@ -118,12 +118,12 @@ TaskCosVertex::~TaskCosVertex()
void TaskCosVertex::updateTask()
{
// blockUpdate = true;
// blockUpdate = true;
// blockUpdate = false;
// blockUpdate = false;
}
void TaskCosVertex::changeEvent(QEvent *e)
void TaskCosVertex::changeEvent(QEvent* e)
{
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
@@ -199,7 +199,7 @@ void TaskCosVertex::onTrackerClicked(bool b)
QString msg = tr("Pick a point for cosmetic vertex");
getMainWindow()->statusBar()->show();
Gui::getMainWindow()->showMessage(msg,3000);
Gui::getMainWindow()->showMessage(msg, 3000);
ui->pbTracker->setText(QString::fromUtf8("Escape picking"));
ui->pbTracker->setEnabled(true);
m_pbTrackerState = TRACKERCANCEL;
@@ -217,22 +217,23 @@ void TaskCosVertex::startTracker(void)
m_tracker = new QGTracker(m_scene, m_trackerMode);
QObject::connect(
m_tracker, SIGNAL(drawingFinished(std::vector<QPointF>, QGIView*)),
this , SLOT (onTrackerFinished(std::vector<QPointF>, QGIView*))
);
} else {
this, SLOT(onTrackerFinished(std::vector<QPointF>, QGIView*))
);
}
else {
//this is too harsh. but need to avoid restarting process
throw Base::RuntimeError("TechDrawNewLeader - tracker already active\n");
}
setEditCursor(Qt::CrossCursor);
QString msg = tr("Left click to set a point");
Gui::getMainWindow()->statusBar()->show();
Gui::getMainWindow()->showMessage(msg,3000);
Gui::getMainWindow()->showMessage(msg, 3000);
}
void TaskCosVertex::onTrackerFinished(std::vector<QPointF> pts, QGIView* qgParent)
{
// Base::Console().Message("TCV::onTrackerFinished()\n");
(void) qgParent;
// Base::Console().Message("TCV::onTrackerFinished()\n");
(void)qgParent;
if (pts.empty()) {
Base::Console().Error("TaskCosVertex - no points available\n");
return;
@@ -279,8 +280,8 @@ void TaskCosVertex::onTrackerFinished(std::vector<QPointF> pts, QGIView* qgParen
void TaskCosVertex::removeTracker(void)
{
// Base::Console().Message("TCV::removeTracker()\n");
if ( (m_tracker != nullptr) &&
(m_tracker->scene() != nullptr) ) {
if ((m_tracker != nullptr) &&
(m_tracker->scene() != nullptr)) {
m_scene->removeItem(m_tracker);
delete m_tracker;
m_tracker = nullptr;
@@ -299,7 +300,7 @@ void TaskCosVertex::abandonEditSession(void)
{
QString msg = tr("In progress edit abandoned. Start over.");
getMainWindow()->statusBar()->show();
Gui::getMainWindow()->showMessage(msg,4000);
Gui::getMainWindow()->showMessage(msg, 4000);
ui->pbTracker->setEnabled(true);
@@ -328,14 +329,14 @@ bool TaskCosVertex::accept()
removeTracker();
double x = ui->dsbX->value().getValue();
double y = ui->dsbY->value().getValue();
QPointF uiPoint(x,-y);
QPointF uiPoint(x, -y);
addCosVertex(uiPoint);
m_baseFeat->recomputeFeature();
m_baseFeat->requestPaint();
m_mdi->setContextMenuPolicy(m_saveContextPolicy);
m_trackerMode = QGTracker::TrackerMode::None;
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
return true;
}
@@ -352,8 +353,8 @@ bool TaskCosVertex::reject()
}
//make sure any dangling objects are cleaned up
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().recompute()");
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
return false;
}
@@ -363,7 +364,7 @@ TaskDlgCosVertex::TaskDlgCosVertex(TechDraw::DrawViewPart* baseFeat,
TechDraw::DrawPage* page)
: TaskDialog()
{
widget = new TaskCosVertex(baseFeat,page);
widget = new TaskCosVertex(baseFeat, page);
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-LeaderLine"),
widget->windowTitle(), true, 0);
taskbox->groupLayout()->addWidget(widget);