From 346e5c6a77e9fce0c5f51bb3b3fcf6c781aea64d Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 27 Aug 2014 13:26:44 +0200 Subject: [PATCH] + fix more compiler warnings --- src/App/FeatureTest.cpp | 2 +- src/Base/FileInfo.cpp | 1 - src/Base/UnitsApi.cpp | 52 +- src/Base/UnitsApi.h | 10 +- src/Gui/DlgCustomizeSpaceball.cpp | 4 +- src/Gui/DlgCustomizeSpaceball.h | 2 +- src/Gui/DlgPreferencesImp.h | 6 +- src/Gui/ViewProvider.cpp | 7 +- src/Gui/propertyeditor/PropertyItem.cpp | 1 - src/Mod/Part/Gui/ViewProviderRuledSurface.cpp | 4 +- src/Mod/Part/Gui/ViewProviderSpline.cpp | 5 +- src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp | 4 +- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 3 - src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 10 +- src/Mod/Sketcher/Gui/SoDatumLabel.cpp | 1 - src/Mod/Sketcher/Gui/TaskSketcherElements.cpp | 604 +++++++++--------- 16 files changed, 380 insertions(+), 336 deletions(-) diff --git a/src/App/FeatureTest.cpp b/src/App/FeatureTest.cpp index 6a34704af..895c543c7 100644 --- a/src/App/FeatureTest.cpp +++ b/src/App/FeatureTest.cpp @@ -119,7 +119,7 @@ FeatureTest::~FeatureTest() DocumentObjectExecReturn *FeatureTest::execute(void) { - int *i,j; + int *i=0,j; float f; void *s; diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index 6e8119f0c..ca60bf1a7 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -301,7 +301,6 @@ bool FileInfo::isWritable () const bool FileInfo::setPermissions (Permissions perms) { - bool ret = false; int mode = 0; if (perms & FileInfo::ReadOnly) diff --git a/src/Base/UnitsApi.cpp b/src/Base/UnitsApi.cpp index 4317153da..465d451a5 100644 --- a/src/Base/UnitsApi.cpp +++ b/src/Base/UnitsApi.cpp @@ -136,26 +136,48 @@ QString UnitsApi::schemaTranslate(Base::Quantity quant,double &factor,QString &u // return PyFloat_FromDouble(Value * UserPrefFactor[t]); //} // -double UnitsApi::toDbl(PyObject *ArgObj,const Base::Unit &u) -{ - if (PyString_Check(ArgObj)) - QString str = QString::fromAscii(PyString_AsString(ArgObj)); - else if (PyFloat_Check(ArgObj)) - double d = PyFloat_AsDouble(ArgObj); - else if (PyInt_Check(ArgObj)) - double d = (double)PyInt_AsLong(ArgObj); - else - throw Base::Exception("Wrong parameter type!"); - return 0.0; +double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u) +{ + if (PyString_Check(ArgObj)) { + // Parse the string + QString str = QString::fromLatin1(PyString_AsString(ArgObj)); + Quantity q = Quantity::parse(str); + if (q.getUnit() == u) + return q.getValue(); + throw Base::Exception("Wrong unit type!"); + } + else if (PyFloat_Check(ArgObj)) { + return PyFloat_AsDouble(ArgObj); + } + else if (PyInt_Check(ArgObj)) { + return static_cast(PyInt_AsLong(ArgObj)); + } + else { + throw Base::Exception("Wrong parameter type!"); + } } -Quantity UnitsApi::toQuantity(PyObject *ArgObj,const Base::Unit &u) +Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u) { + double d; + if (PyString_Check(ArgObj)) { + // Parse the string + QString str = QString::fromLatin1(PyString_AsString(ArgObj)); + Quantity q = Quantity::parse(str); + d = q.getValue(); + } + else if (PyFloat_Check(ArgObj)) { + d = PyFloat_AsDouble(ArgObj); + } + else if (PyInt_Check(ArgObj)) { + d = static_cast(PyInt_AsLong(ArgObj)); + } + else { + throw Base::Exception("Wrong parameter type!"); + } - - - return Quantity(); + return Quantity(d,u); } void UnitsApi::setDecimals(int prec) diff --git a/src/Base/UnitsApi.h b/src/Base/UnitsApi.h index 584319830..153cd93ad 100644 --- a/src/Base/UnitsApi.h +++ b/src/Base/UnitsApi.h @@ -65,11 +65,11 @@ public: static UnitSystem getSchema(void){return actSystem;} static QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString); - static QString schemaTranslate(Base::Quantity quant){ // to satisfy GCC - double dummy1; - QString dummy2; - return UnitsApi::schemaTranslate(quant,dummy1,dummy2); - } + static QString schemaTranslate(Base::Quantity quant){ // to satisfy GCC + double dummy1; + QString dummy2; + return UnitsApi::schemaTranslate(quant,dummy1,dummy2); + } /// generate a value for a quantity with default user prefered system static double toDbl(PyObject *ArgObj,const Base::Unit &u=Base::Unit()); /// generate a value for a quantity with default user prefered system diff --git a/src/Gui/DlgCustomizeSpaceball.cpp b/src/Gui/DlgCustomizeSpaceball.cpp index dc89ce9fc..6c962c992 100644 --- a/src/Gui/DlgCustomizeSpaceball.cpp +++ b/src/Gui/DlgCustomizeSpaceball.cpp @@ -108,7 +108,7 @@ QVariant ButtonModel::data (const QModelIndex &index, int role) const return QVariant(); } -void ButtonModel::insertRows(int number) +void ButtonModel::insertButtonRows(int number) { int buttonCount = spaceballButtonGroup()->GetGroups().size(); beginInsertRows(QModelIndex(), buttonCount, number-buttonCount+1); @@ -134,7 +134,7 @@ void ButtonModel::goButtonPress(int number) QString numberString; numberString.setNum(number); if (!spaceballButtonGroup()->HasGroup(numberString.toAscii())) - insertRows(number); + insertButtonRows(number); } void ButtonModel::goMacroRemoved(const QByteArray& macroName) diff --git a/src/Gui/DlgCustomizeSpaceball.h b/src/Gui/DlgCustomizeSpaceball.h index d3a35f2c3..315c8af1d 100644 --- a/src/Gui/DlgCustomizeSpaceball.h +++ b/src/Gui/DlgCustomizeSpaceball.h @@ -57,7 +57,7 @@ namespace Gui ButtonModel(QObject *parent); virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - void insertRows(int number); + void insertButtonRows(int number); void setCommand(int row, QString command); void goButtonPress(int number); void goMacroRemoved(const QByteArray& macroName); diff --git a/src/Gui/DlgPreferencesImp.h b/src/Gui/DlgPreferencesImp.h index 878628347..5757daf6f 100644 --- a/src/Gui/DlgPreferencesImp.h +++ b/src/Gui/DlgPreferencesImp.h @@ -122,8 +122,8 @@ protected: void changeEvent(QEvent *e); void showEvent(QShowEvent*); void resizeEvent(QResizeEvent*); - -protected Q_SLOTS: + +protected Q_SLOTS: void changeGroup(QListWidgetItem *current, QListWidgetItem *previous); void on_buttonBox_clicked(QAbstractButton*); void resizeWindow(int w, int h); @@ -138,9 +138,9 @@ private: private: typedef std::pair > TGroupPages; static std::list _pages; /**< Name of all registered preference pages */ + Ui_DlgPreferences* ui; bool invalidParameter; bool canEmbedScrollArea; - Ui_DlgPreferences* ui; }; } // namespace Dialog diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index dcdede3e1..548ac0913 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -61,7 +61,12 @@ using namespace Gui; PROPERTY_SOURCE_ABSTRACT(Gui::ViewProvider, App::PropertyContainer) ViewProvider::ViewProvider() - : pcAnnotation(0), pyViewObject(0), _iActualMode(-1), _iEditMode(-1), _updateData(true), viewOverrideMode(-1) + : pcAnnotation(0) + , pyViewObject(0) + , _iActualMode(-1) + , _iEditMode(-1) + , viewOverrideMode(-1) + , _updateData(true) { pcRoot = new SoSeparator(); pcRoot->ref(); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 678cd531f..4256fea9f 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -1010,7 +1010,6 @@ void PropertyVectorDistanceItem::setValue(const QVariant& variant) q = Base::Quantity(value.y, Base::Unit::Length); unit + QString::fromLatin1("'%1 %2'").arg(q.getValue()).arg(q.getUnit().getString()); q = Base::Quantity(value.z, Base::Unit::Length); - QString::fromLatin1("'%1 %2')").arg(q.getValue()).arg(q.getUnit().getString()); setPropertyValue(unit); } diff --git a/src/Mod/Part/Gui/ViewProviderRuledSurface.cpp b/src/Mod/Part/Gui/ViewProviderRuledSurface.cpp index cf3a09bd8..b20e72b4f 100644 --- a/src/Mod/Part/Gui/ViewProviderRuledSurface.cpp +++ b/src/Mod/Part/Gui/ViewProviderRuledSurface.cpp @@ -71,8 +71,8 @@ void ViewProviderRuledSurface::updateData(const App::Property* prop) { PartGui::ViewProviderPart::updateData(prop); if (prop->getTypeId() == Part::PropertyShapeHistory::getClassTypeId()) { - const std::vector& hist = static_cast - (prop)->getValues(); + //const std::vector& hist = static_cast + // (prop)->getValues(); } /* //The following hides the Children shapes. If the edges from which the Ruled Surface was created * were selected from the subshapes of another shape, it is likely that one would not want to hide the shape diff --git a/src/Mod/Part/Gui/ViewProviderSpline.cpp b/src/Mod/Part/Gui/ViewProviderSpline.cpp index d1cccd3ee..2183cbebc 100644 --- a/src/Mod/Part/Gui/ViewProviderSpline.cpp +++ b/src/Mod/Part/Gui/ViewProviderSpline.cpp @@ -37,6 +37,7 @@ # include # include # include +# include # include # include # include @@ -111,7 +112,7 @@ void ViewProviderSpline::showControlPoints(bool show, const App::Property* prop) for (TopExp_Explorer xp(shape, TopAbs_SHELL); xp.More(); xp.Next()) { const TopoDS_Shell& shell = TopoDS::Shell(xp.Current()); - for (TopExp_Explorer xp2(xp.Current(), TopAbs_FACE); xp2.More(); xp2.Next()) { + for (TopExp_Explorer xp2(shell, TopAbs_FACE); xp2.More(); xp2.Next()) { const TopoDS_Face& face = TopoDS::Face(xp2.Current()); showControlPointsOfFace(face); } @@ -122,7 +123,7 @@ void ViewProviderSpline::showControlPoints(bool show, const App::Property* prop) } for (TopExp_Explorer xp(shape, TopAbs_WIRE, TopAbs_FACE); xp.More(); xp.Next()) { const TopoDS_Wire& wire = TopoDS::Wire(xp.Current()); - for (TopExp_Explorer xp2(xp.Current(), TopAbs_EDGE); xp2.More(); xp2.Next()) { + for (TopExp_Explorer xp2(wire, TopAbs_EDGE); xp2.More(); xp2.Next()) { const TopoDS_Edge& edge = TopoDS::Edge(xp2.Current()); showControlPointsOfEdge(edge); } diff --git a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp index 5f1ccc9f5..9bb6ace5d 100644 --- a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp +++ b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp @@ -88,9 +88,7 @@ void CmdSketcherToggleConstruction::activated(int iMsg) // get the needed lists and objects const std::vector &SubNames = selection[0].getSubNames(); - Sketcher::SketchObject* Obj = dynamic_cast(selection[0].getObject()); - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); - + // undo command open openCommand("toggle draft from/to draft"); diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 57754adaa..9eae22b5d 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -2925,9 +2925,6 @@ public: EditCurve[35] = EditCurve[0] ; //EditCurve[34] = EditCurve[0]; - // Display radius for user - float radius = (onSketchPos - EditCurve[0]).Length(); - SbString text; text.sprintf(" (%.1fR %.1fL)", r,lx); setPositionText(onSketchPos, text); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 803bf0965..1559de143 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -341,6 +341,8 @@ void DrawSketchHandler::createAutoConstraints(const std::vector ,geoId1, it->GeoId ); } break; + default: + break; } Gui::Command::commitCommand(); @@ -387,10 +389,14 @@ void DrawSketchHandler::renderSuggestConstraintsCursor(std::vectorparam1.getValue(); float startangle = this->param2.getValue(); float range = this->param3.getValue(); - float endangle = startangle + range; float r = 2*length; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 74c9e9108..d968e89e4 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2014 Abdullah Tahiri commandManager().getCommandByName(CMDSTR)->getAccel()))); \ +#define CONTEXT_ITEM(ICONSTR,NAMESTR,CMDSTR,FUNC,ACTSONSELECTION) \ +QIcon icon_ ## FUNC( Gui::BitmapFactory().pixmap(ICONSTR) ); \ + QAction* constr_ ## FUNC = menu.addAction(icon_ ## FUNC,tr(NAMESTR), this, SLOT(FUNC()), \ + QKeySequence(QString::fromUtf8(Gui::Application::Instance->commandManager().getCommandByName(CMDSTR)->getAccel()))); \ if(ACTSONSELECTION) constr_ ## FUNC->setEnabled(!items.isEmpty()); else constr_ ## FUNC->setEnabled(true); /// Defines the member function corresponding to the CONTEXT_ITEM macro -#define CONTEXT_MEMBER_DEF(CMDSTR,FUNC) \ -void ElementView::FUNC(){ \ +#define CONTEXT_MEMBER_DEF(CMDSTR,FUNC) \ +void ElementView::FUNC(){ \ Gui::Application::Instance->commandManager().runCommandByName(CMDSTR);} - + // helper class to store additional information about the listWidget entry. class ElementItem : public QListWidgetItem { public: - ElementItem( const QIcon & icon, const QString & text, int elementnr, - int startingVertex, int midVertex, int endVertex, - Base::Type geometryType) - : QListWidgetItem(icon,text),ElementNbr(elementnr), - StartingVertex(startingVertex), MidVertex(midVertex), EndVertex(endVertex), - GeometryType(geometryType),isLineSelected(false), - isStartingPointSelected(false),isEndPointSelected(false),isMidPointSelected(false) + ElementItem(const QIcon & icon, const QString & text, int elementnr, + int startingVertex, int midVertex, int endVertex, + Base::Type geometryType) + : QListWidgetItem(icon,text) + , ElementNbr(elementnr) + , StartingVertex(startingVertex) + , MidVertex(midVertex) + , EndVertex(endVertex) + , isLineSelected(false) + , isStartingPointSelected(false) + , isEndPointSelected(false) + , isMidPointSelected(false) + , GeometryType(geometryType) { } - ElementItem( const QString & text,int elementnr, - int startingVertex, int midVertex, int endVertex, - Base::Type geometryType) - : QListWidgetItem(text),ElementNbr(elementnr), - StartingVertex(startingVertex), MidVertex(midVertex), EndVertex(endVertex), - GeometryType(geometryType),isLineSelected(false), - isStartingPointSelected(false),isEndPointSelected(false),isMidPointSelected(false) + ElementItem(const QString & text,int elementnr, + int startingVertex, int midVertex, int endVertex, + Base::Type geometryType) + : QListWidgetItem(text) + , ElementNbr(elementnr) + , StartingVertex(startingVertex) + , MidVertex(midVertex) + , EndVertex(endVertex) + , isLineSelected(false) + , isStartingPointSelected(false) + , isEndPointSelected(false) + , isMidPointSelected(false) + , GeometryType(geometryType) { } @@ -118,7 +130,6 @@ ElementView::~ElementView() void ElementView::contextMenuEvent (QContextMenuEvent* event) { QMenu menu; - QListWidgetItem* item = currentItem(); QList items = selectedItems(); // CONTEXT_ITEM(ICONSTR,NAMESTR,FUNC,KEY) @@ -138,11 +149,11 @@ void ElementView::contextMenuEvent (QContextMenuEvent* event) CONTEXT_ITEM("Constraint_Radius","Radius Constraint","Sketcher_ConstrainRadius",doRadiusConstraint,true) CONTEXT_ITEM("Constraint_InternalAngle","Angle Constraint","Sketcher_ConstrainAngle",doAngleConstraint,true) - QAction* sep = menu.addSeparator(); + menu.addSeparator(); CONTEXT_ITEM("Sketcher_AlterConstruction","Toggle construction line","Sketcher_ToggleConstruction",doToggleConstruction,true) - QAction* sep1 = menu.addSeparator(); + menu.addSeparator(); CONTEXT_ITEM("Sketcher_CloseShape","Close Shape","Sketcher_CloseShape",doCloseShape,true) CONTEXT_ITEM("Sketcher_ConnectLines","Connect","Sketcher_ConnectLines",doConnect,true) @@ -151,7 +162,7 @@ void ElementView::contextMenuEvent (QContextMenuEvent* event) CONTEXT_ITEM("Sketcher_SelectHorizontalAxis","Select Horizontal Axis","Sketcher_SelectHorizontalAxis",doSelectHAxis,false) CONTEXT_ITEM("Sketcher_SelectVerticalAxis","Select Vertical Axis","Sketcher_SelectVerticalAxis",doSelectVAxis,false) - QAction* sep2 = menu.addSeparator(); + menu.addSeparator(); QAction* remove = menu.addAction(tr("Delete"), this, SLOT(deleteSelectedItems()), QKeySequence(QKeySequence::Delete)); @@ -207,24 +218,29 @@ void ElementView::keyPressEvent(QKeyEvent * event) switch (event->key()) { case Qt::Key_Z: - // signal - onFilterShortcutPressed(); - break; + // signal + onFilterShortcutPressed(); + break; default: - QListWidget::keyPressEvent( event ); - break; + QListWidget::keyPressEvent( event ); + break; } } + // ---------------------------------------------------------------------------- TaskSketcherElements::TaskSketcherElements(ViewProviderSketch *sketchView) - : TaskBox(Gui::BitmapFactory().pixmap("document-new"),tr("Elements"),true, 0), - sketchView(sketchView), inhibitSelectionUpdate(false), focusItemIndex(-1), - isNamingBoxChecked(false), isautoSwitchBoxChecked(false), previouslySelectedItemIndex(-1) + : TaskBox(Gui::BitmapFactory().pixmap("document-new"),tr("Elements"),true, 0) + , sketchView(sketchView) + , ui(new Ui_TaskSketcherElements()) + , focusItemIndex(-1) + , previouslySelectedItemIndex(-1) + , isNamingBoxChecked(false) + , isautoSwitchBoxChecked(false) + , inhibitSelectionUpdate(false) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskSketcherElements(); ui->setupUi(proxy); ui->listWidgetElements->setSelectionMode(QAbstractItemView::ExtendedSelection); ui->listWidgetElements->setEditTriggers(QListWidget::NoEditTriggers); @@ -287,7 +303,7 @@ void TaskSketcherElements::onSelectionChanged(const Gui::SelectionChanges& msg) { std::string temp; if (msg.Type == Gui::SelectionChanges::ClrSelection) { - clearWidget(); + clearWidget(); } else if (msg.Type == Gui::SelectionChanges::AddSelection || msg.Type == Gui::SelectionChanges::RmvSelection) { @@ -297,89 +313,91 @@ void TaskSketcherElements::onSelectionChanged(const Gui::SelectionChanges& msg) strcmp(msg.pObjectName,sketchView->getSketchObject()->getNameInDocument())== 0) { if (msg.pSubName) { QString expr = QString::fromAscii(msg.pSubName); - std::string shapetype(msg.pSubName); - // if-else edge vertex - if (shapetype.size() > 4 && shapetype.substr(0,4) == "Edge") - { - QRegExp rx(QString::fromAscii("^Edge(\\d+)$")); - int pos = expr.indexOf(rx); - if (pos > -1) { - bool ok; - int ElementId = rx.cap(1).toInt(&ok) - 1; - if (ok) { - int countItems = ui->listWidgetElements->count(); - for (int i=0; i < countItems; i++) { - ElementItem* item = static_cast - (ui->listWidgetElements->item(i)); - if (item->ElementNbr == ElementId) { - item->isLineSelected=select; - break; - } - } - } - } - } - else if (shapetype.size() > 6 && shapetype.substr(0,6) == "Vertex"){ - QRegExp rx(QString::fromAscii("^Vertex(\\d+)$")); - int pos = expr.indexOf(rx); - if (pos > -1) { - bool ok; - int ElementId = rx.cap(1).toInt(&ok) - 1; - if (ok) { - // Get the GeoID&Pos - int GeoId; - Sketcher::PointPos PosId; - sketchView->getSketchObject()->getGeoVertexIndex(ElementId,GeoId, PosId); - - int countItems = ui->listWidgetElements->count(); - for (int i=0; i < countItems; i++) { - ElementItem* item = static_cast - (ui->listWidgetElements->item(i)); - if (item->ElementNbr == GeoId) { - switch(PosId) - { - case Sketcher::start: - item->isStartingPointSelected=select; - break; - case Sketcher::end: - item->isEndPointSelected=select; - break; - case Sketcher::mid: - item->isMidPointSelected=select; - break; - } - break; - } - } - } - } - } - // update the listwidget - int element=ui->comboBoxElementFilter->currentIndex(); + std::string shapetype(msg.pSubName); + // if-else edge vertex + if (shapetype.size() > 4 && shapetype.substr(0,4) == "Edge") + { + QRegExp rx(QString::fromAscii("^Edge(\\d+)$")); + int pos = expr.indexOf(rx); + if (pos > -1) { + bool ok; + int ElementId = rx.cap(1).toInt(&ok) - 1; + if (ok) { + int countItems = ui->listWidgetElements->count(); + for (int i=0; i < countItems; i++) { + ElementItem* item = static_cast + (ui->listWidgetElements->item(i)); + if (item->ElementNbr == ElementId) { + item->isLineSelected=select; + break; + } + } + } + } + } + else if (shapetype.size() > 6 && shapetype.substr(0,6) == "Vertex"){ + QRegExp rx(QString::fromAscii("^Vertex(\\d+)$")); + int pos = expr.indexOf(rx); + if (pos > -1) { + bool ok; + int ElementId = rx.cap(1).toInt(&ok) - 1; + if (ok) { + // Get the GeoID&Pos + int GeoId; + Sketcher::PointPos PosId; + sketchView->getSketchObject()->getGeoVertexIndex(ElementId,GeoId, PosId); - ui->listWidgetElements->blockSignals(true); + int countItems = ui->listWidgetElements->count(); + for (int i=0; i < countItems; i++) { + ElementItem* item = static_cast + (ui->listWidgetElements->item(i)); + if (item->ElementNbr == GeoId) { + switch(PosId) + { + case Sketcher::start: + item->isStartingPointSelected=select; + break; + case Sketcher::end: + item->isEndPointSelected=select; + break; + case Sketcher::mid: + item->isMidPointSelected=select; + break; + default: + break; + } + break; + } + } + } + } + } + // update the listwidget + int element=ui->comboBoxElementFilter->currentIndex(); + + ui->listWidgetElements->blockSignals(true); - for (int i=0;ilistWidgetElements->count(); i++) { - ElementItem * ite=static_cast(ui->listWidgetElements->item(i)); - - switch(element){ - case 0: - ite->setSelected(ite->isLineSelected); - break; - case 1: - ite->setSelected(ite->isStartingPointSelected); - break; - case 2: - ite->setSelected(ite->isEndPointSelected); - break; - case 3: - ite->setSelected(ite->isMidPointSelected); - break; - } - } + for (int i=0;ilistWidgetElements->count(); i++) { + ElementItem * ite=static_cast(ui->listWidgetElements->item(i)); - ui->listWidgetElements->blockSignals(false); + switch(element){ + case 0: + ite->setSelected(ite->isLineSelected); + break; + case 1: + ite->setSelected(ite->isStartingPointSelected); + break; + case 2: + ite->setSelected(ite->isEndPointSelected); + break; + case 3: + ite->setSelected(ite->isMidPointSelected); + break; + } + } + + ui->listWidgetElements->blockSignals(false); } } @@ -409,37 +427,37 @@ void TaskSketcherElements::on_listWidgetElements_itemSelectionChanged(void) bool multipleselection=true; // ctrl type of selection in listWidget bool multipleconsecutiveselection=false; // shift type of selection in listWidget - if(!inhibitSelectionUpdate){ + if(!inhibitSelectionUpdate){ if(itf!=NULL) { - switch(element){ - case 0: - itf->isLineSelected=!itf->isLineSelected; - break; - case 1: - itf->isStartingPointSelected=!itf->isStartingPointSelected; - break; - case 2: - itf->isEndPointSelected=!itf->isEndPointSelected; - break; - case 3: - itf->isMidPointSelected=!itf->isMidPointSelected; - break; - } + switch(element){ + case 0: + itf->isLineSelected=!itf->isLineSelected; + break; + case 1: + itf->isStartingPointSelected=!itf->isStartingPointSelected; + break; + case 2: + itf->isEndPointSelected=!itf->isEndPointSelected; + break; + case 3: + itf->isMidPointSelected=!itf->isMidPointSelected; + break; + } } if(QApplication::keyboardModifiers()==Qt::ControlModifier)// multiple ctrl selection? - multipleselection=true; + multipleselection=true; else - multipleselection=false; + multipleselection=false; if(QApplication::keyboardModifiers()==Qt::ShiftModifier)// multiple shift selection? - multipleconsecutiveselection=true; + multipleconsecutiveselection=true; else - multipleconsecutiveselection=false; + multipleconsecutiveselection=false; if(multipleselection && multipleconsecutiveselection){ // ctrl takes priority over shift functionality - multipleselection=true; - multipleconsecutiveselection=false; + multipleselection=true; + multipleconsecutiveselection=false; } } @@ -448,92 +466,92 @@ void TaskSketcherElements::on_listWidgetElements_itemSelectionChanged(void) bool block = this->blockConnection(true); // avoid to be notified by itself Gui::Selection().clearSelection(); - + for (int i=0;ilistWidgetElements->count(); i++) { - ElementItem * ite=static_cast(ui->listWidgetElements->item(i)); - - if(multipleselection==false && multipleconsecutiveselection==false && ite!=itf) - { - ite->isLineSelected=false; - ite->isStartingPointSelected=false; - ite->isEndPointSelected=false; - ite->isMidPointSelected=false; - } - - if(multipleconsecutiveselection==true) - { - if( (( i>focusItemIndex && ipreviouslySelectedItemIndex )) && - previouslySelectedItemIndex>=0){ - // select the element of the Item - switch(element){ - case 0: - ite->isLineSelected=true; - break; - case 1: - ite->isStartingPointSelected=true; - break; - case 2: - ite->isEndPointSelected=true; - break; - case 3: - ite->isMidPointSelected=true; - break; - } - } - } - - // first update the listwidget - switch(element){ - case 0: - ite->setSelected(ite->isLineSelected); - break; - case 1: - ite->setSelected(ite->isStartingPointSelected); - break; - case 2: - ite->setSelected(ite->isEndPointSelected); - break; - case 3: - ite->setSelected(ite->isMidPointSelected); - break; - } - - // now the scene - std::stringstream ss; - int vertex; - - if(ite->isLineSelected){ - ss << "Edge" << ite->ElementNbr + 1; - Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); - } - - if(ite->isStartingPointSelected){ - ss.str(std::string()); - vertex= ite->StartingVertex; - if(vertex!=-1){ - ss << "Vertex" << vertex + 1; - Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); - } - } - - if(ite->isEndPointSelected){ - ss.str(std::string()); - vertex= ite->EndVertex; - if(vertex!=-1){ - ss << "Vertex" << vertex + 1; - Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); - } - } - - if(ite->isMidPointSelected){ - ss.str(std::string()); - vertex= ite->MidVertex; - if(vertex!=-1){ - ss << "Vertex" << vertex + 1; - Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); - } - } + ElementItem * ite=static_cast(ui->listWidgetElements->item(i)); + + if(multipleselection==false && multipleconsecutiveselection==false && ite!=itf) + { + ite->isLineSelected=false; + ite->isStartingPointSelected=false; + ite->isEndPointSelected=false; + ite->isMidPointSelected=false; + } + + if(multipleconsecutiveselection==true) + { + if( (( i>focusItemIndex && ipreviouslySelectedItemIndex )) && + previouslySelectedItemIndex>=0){ + // select the element of the Item + switch(element){ + case 0: + ite->isLineSelected=true; + break; + case 1: + ite->isStartingPointSelected=true; + break; + case 2: + ite->isEndPointSelected=true; + break; + case 3: + ite->isMidPointSelected=true; + break; + } + } + } + + // first update the listwidget + switch(element){ + case 0: + ite->setSelected(ite->isLineSelected); + break; + case 1: + ite->setSelected(ite->isStartingPointSelected); + break; + case 2: + ite->setSelected(ite->isEndPointSelected); + break; + case 3: + ite->setSelected(ite->isMidPointSelected); + break; + } + + // now the scene + std::stringstream ss; + int vertex; + + if(ite->isLineSelected){ + ss << "Edge" << ite->ElementNbr + 1; + Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + } + + if(ite->isStartingPointSelected){ + ss.str(std::string()); + vertex= ite->StartingVertex; + if(vertex!=-1){ + ss << "Vertex" << vertex + 1; + Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + } + } + + if(ite->isEndPointSelected){ + ss.str(std::string()); + vertex= ite->EndVertex; + if(vertex!=-1){ + ss << "Vertex" << vertex + 1; + Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + } + } + + if(ite->isMidPointSelected){ + ss.str(std::string()); + vertex= ite->MidVertex; + if(vertex!=-1){ + ss << "Vertex" << vertex + 1; + Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + } + } } this->blockConnection(block); ui->listWidgetElements->blockSignals(false); @@ -572,7 +590,7 @@ void TaskSketcherElements::on_listWidgetElements_itemEntered(QListWidgetItem *it } int element=ui->comboBoxElementFilter->currentIndex(); - + focusItemIndex=tempitemindex; int vertex; @@ -580,18 +598,18 @@ void TaskSketcherElements::on_listWidgetElements_itemEntered(QListWidgetItem *it switch(element) { case 0: - ss << "Edge" << it->ElementNbr + 1; - Gui::Selection().setPreselect(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); - break; + ss << "Edge" << it->ElementNbr + 1; + Gui::Selection().setPreselect(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + break; case 1: case 2: - case 3: - vertex= sketchView->getSketchObject()->getVertexIndexGeoPos(it->ElementNbr,static_cast(element)); - if(vertex!=-1){ - ss << "Vertex" << vertex + 1; - Gui::Selection().setPreselect(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); - } - break; + case 3: + vertex= sketchView->getSketchObject()->getVertexIndexGeoPos(it->ElementNbr,static_cast(element)); + if(vertex!=-1){ + ss << "Vertex" << vertex + 1; + Gui::Selection().setPreselect(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); + } + break; } } @@ -631,37 +649,37 @@ void TaskSketcherElements::slotElementsChanged(void) Base::Type type = (*it)->getTypeId(); ui->listWidgetElements->addItem(new ElementItem( - (type == Part::GeomPoint::getClassTypeId() && element==1) ? Sketcher_Element_Point_StartingPoint : - (type == Part::GeomLineSegment::getClassTypeId() && element==0) ? Sketcher_Element_Line_Edge : - (type == Part::GeomLineSegment::getClassTypeId() && element==1) ? Sketcher_Element_Line_StartingPoint : - (type == Part::GeomLineSegment::getClassTypeId() && element==2) ? Sketcher_Element_Line_EndPoint : - (type == Part::GeomArcOfCircle::getClassTypeId() && element==0) ? Sketcher_Element_Arc_Edge : - (type == Part::GeomArcOfCircle::getClassTypeId() && element==1) ? Sketcher_Element_Arc_StartingPoint : - (type == Part::GeomArcOfCircle::getClassTypeId() && element==2) ? Sketcher_Element_Arc_EndPoint : - (type == Part::GeomArcOfCircle::getClassTypeId() && element==3) ? Sketcher_Element_Arc_MidPoint : - (type == Part::GeomCircle::getClassTypeId() && element==0) ? Sketcher_Element_Circle_Edge : - (type == Part::GeomCircle::getClassTypeId() && element==3) ? Sketcher_Element_Circle_MidPoint : - none, - type == Part::GeomPoint::getClassTypeId() ? ( isNamingBoxChecked ? - (tr("Point") + QString::fromLatin1("(Edge%1)").arg(i)): - (QString::fromLatin1("%1-").arg(i)+tr("Point"))) : - type == Part::GeomLineSegment::getClassTypeId() ? ( isNamingBoxChecked ? - (tr("Line") + QString::fromLatin1("(Edge%1)").arg(i)): - (QString::fromLatin1("%1-").arg(i)+tr("Line"))) : - type == Part::GeomArcOfCircle::getClassTypeId() ? ( isNamingBoxChecked ? - (tr("Arc") + QString::fromLatin1("(Edge%1)").arg(i)): - (QString::fromLatin1("%1-").arg(i)+tr("Arc"))) : - type == Part::GeomCircle::getClassTypeId() ? ( isNamingBoxChecked ? - (tr("Circle") + QString::fromLatin1("(Edge%1)").arg(i)): - (QString::fromLatin1("%1-").arg(i)+tr("Circle"))) : - ( isNamingBoxChecked ? - (tr("Other") + QString::fromLatin1("(Edge%1)").arg(i)): - (QString::fromLatin1("%1-").arg(i)+tr("Other"))), - i-1, - sketchView->getSketchObject()->getVertexIndexGeoPos(i-1,Sketcher::start), - sketchView->getSketchObject()->getVertexIndexGeoPos(i-1,Sketcher::mid), - sketchView->getSketchObject()->getVertexIndexGeoPos(i-1,Sketcher::end), - type)); + (type == Part::GeomPoint::getClassTypeId() && element==1) ? Sketcher_Element_Point_StartingPoint : + (type == Part::GeomLineSegment::getClassTypeId() && element==0) ? Sketcher_Element_Line_Edge : + (type == Part::GeomLineSegment::getClassTypeId() && element==1) ? Sketcher_Element_Line_StartingPoint : + (type == Part::GeomLineSegment::getClassTypeId() && element==2) ? Sketcher_Element_Line_EndPoint : + (type == Part::GeomArcOfCircle::getClassTypeId() && element==0) ? Sketcher_Element_Arc_Edge : + (type == Part::GeomArcOfCircle::getClassTypeId() && element==1) ? Sketcher_Element_Arc_StartingPoint : + (type == Part::GeomArcOfCircle::getClassTypeId() && element==2) ? Sketcher_Element_Arc_EndPoint : + (type == Part::GeomArcOfCircle::getClassTypeId() && element==3) ? Sketcher_Element_Arc_MidPoint : + (type == Part::GeomCircle::getClassTypeId() && element==0) ? Sketcher_Element_Circle_Edge : + (type == Part::GeomCircle::getClassTypeId() && element==3) ? Sketcher_Element_Circle_MidPoint : + none, + type == Part::GeomPoint::getClassTypeId() ? ( isNamingBoxChecked ? + (tr("Point") + QString::fromLatin1("(Edge%1)").arg(i)): + (QString::fromLatin1("%1-").arg(i)+tr("Point"))) : + type == Part::GeomLineSegment::getClassTypeId() ? ( isNamingBoxChecked ? + (tr("Line") + QString::fromLatin1("(Edge%1)").arg(i)): + (QString::fromLatin1("%1-").arg(i)+tr("Line"))) : + type == Part::GeomArcOfCircle::getClassTypeId() ? ( isNamingBoxChecked ? + (tr("Arc") + QString::fromLatin1("(Edge%1)").arg(i)): + (QString::fromLatin1("%1-").arg(i)+tr("Arc"))) : + type == Part::GeomCircle::getClassTypeId() ? ( isNamingBoxChecked ? + (tr("Circle") + QString::fromLatin1("(Edge%1)").arg(i)): + (QString::fromLatin1("%1-").arg(i)+tr("Circle"))) : + ( isNamingBoxChecked ? + (tr("Other") + QString::fromLatin1("(Edge%1)").arg(i)): + (QString::fromLatin1("%1-").arg(i)+tr("Other"))), + i-1, + sketchView->getSketchObject()->getVertexIndexGeoPos(i-1,Sketcher::start), + sketchView->getSketchObject()->getVertexIndexGeoPos(i-1,Sketcher::mid), + sketchView->getSketchObject()->getVertexIndexGeoPos(i-1,Sketcher::end), + type)); } } @@ -684,22 +702,22 @@ void TaskSketcherElements::on_listWidgetElements_filterShortcutPressed() switch(element) { - case 0: // Edge - element = ( type == Part::GeomCircle::getClassTypeId() ) ? 3 : 1; - break; - case 1: // StartingPoint - element = ( type == Part::GeomCircle::getClassTypeId() ) ? 3 : - ( type == Part::GeomPoint::getClassTypeId() ) ? 1 : 2; - break; - case 2: // EndPoint - element = ( type == Part::GeomLineSegment::getClassTypeId() ) ? 0 : - ( type == Part::GeomPoint::getClassTypeId() ) ? 1 : 3; - break; - case 3: // MidPoint - element = ( type == Part::GeomPoint::getClassTypeId() ) ? 1 : 0; - break; - default: - element = 0; + case 0: // Edge + element = ( type == Part::GeomCircle::getClassTypeId() ) ? 3 : 1; + break; + case 1: // StartingPoint + element = ( type == Part::GeomCircle::getClassTypeId() ) ? 3 : + ( type == Part::GeomPoint::getClassTypeId() ) ? 1 : 2; + break; + case 2: // EndPoint + element = ( type == Part::GeomLineSegment::getClassTypeId() ) ? 0 : + ( type == Part::GeomPoint::getClassTypeId() ) ? 1 : 3; + break; + case 3: // MidPoint + element = ( type == Part::GeomPoint::getClassTypeId() ) ? 1 : 0; + break; + default: + element = 0; } ui->comboBoxElementFilter->setCurrentIndex(element); @@ -710,8 +728,8 @@ void TaskSketcherElements::on_listWidgetElements_filterShortcutPressed() } else{ element = (ui->comboBoxElementFilter->currentIndex()+1) % - ui->comboBoxElementFilter->count(); - + ui->comboBoxElementFilter->count(); + ui->comboBoxElementFilter->setCurrentIndex(element); Gui::Selection().rmvPreselect(); @@ -769,7 +787,7 @@ void TaskSketcherElements::clearWidget() item->isLineSelected=false; item->isStartingPointSelected=false; item->isEndPointSelected=false; - item->isMidPointSelected=false; + item->isMidPointSelected=false; } } @@ -791,17 +809,17 @@ void TaskSketcherElements::updateIcons(int element) Base::Type type = static_cast(ui->listWidgetElements->item(i))->GeometryType; ui->listWidgetElements->item(i)->setIcon( - (type == Part::GeomPoint::getClassTypeId() && element==1) ? Sketcher_Element_Point_StartingPoint : - (type == Part::GeomLineSegment::getClassTypeId() && element==0) ? Sketcher_Element_Line_Edge : - (type == Part::GeomLineSegment::getClassTypeId() && element==1) ? Sketcher_Element_Line_StartingPoint : - (type == Part::GeomLineSegment::getClassTypeId() && element==2) ? Sketcher_Element_Line_EndPoint : - (type == Part::GeomArcOfCircle::getClassTypeId() && element==0) ? Sketcher_Element_Arc_Edge : - (type == Part::GeomArcOfCircle::getClassTypeId() && element==1) ? Sketcher_Element_Arc_StartingPoint : - (type == Part::GeomArcOfCircle::getClassTypeId() && element==2) ? Sketcher_Element_Arc_EndPoint : - (type == Part::GeomArcOfCircle::getClassTypeId() && element==3) ? Sketcher_Element_Arc_MidPoint : - (type == Part::GeomCircle::getClassTypeId() && element==0) ? Sketcher_Element_Circle_Edge : - (type == Part::GeomCircle::getClassTypeId() && element==3) ? Sketcher_Element_Circle_MidPoint : - none); + (type == Part::GeomPoint::getClassTypeId() && element==1) ? Sketcher_Element_Point_StartingPoint : + (type == Part::GeomLineSegment::getClassTypeId() && element==0) ? Sketcher_Element_Line_Edge : + (type == Part::GeomLineSegment::getClassTypeId() && element==1) ? Sketcher_Element_Line_StartingPoint : + (type == Part::GeomLineSegment::getClassTypeId() && element==2) ? Sketcher_Element_Line_EndPoint : + (type == Part::GeomArcOfCircle::getClassTypeId() && element==0) ? Sketcher_Element_Arc_Edge : + (type == Part::GeomArcOfCircle::getClassTypeId() && element==1) ? Sketcher_Element_Arc_StartingPoint : + (type == Part::GeomArcOfCircle::getClassTypeId() && element==2) ? Sketcher_Element_Arc_EndPoint : + (type == Part::GeomArcOfCircle::getClassTypeId() && element==3) ? Sketcher_Element_Arc_MidPoint : + (type == Part::GeomCircle::getClassTypeId() && element==0) ? Sketcher_Element_Circle_Edge : + (type == Part::GeomCircle::getClassTypeId() && element==3) ? Sketcher_Element_Circle_MidPoint : + none); } }