+ add method to get SoDetail from element name

+ fix broken selection mechanism

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5260 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
wmayer 2011-12-10 21:11:20 +00:00
parent d5655a9e1d
commit e95de7090d
10 changed files with 92 additions and 55 deletions

View File

@ -251,14 +251,26 @@ void SoFCUnifiedSelection::doAction(SoAction *action)
App::DocumentObject* obj = doc->getObject(selaction->SelChange.pObjectName);
ViewProvider*vp = Application::Instance->getViewProvider(obj);
if (vp && vp->useNewSelectionModel() && vp->isSelectable()) {
SoDetail* detail = vp->getDetail(selaction->SelChange.pSubName);
SoSelectionElementAction::Type type = SoSelectionElementAction::None;
if (selaction->SelChange.Type == SelectionChanges::AddSelection)
type = SoSelectionElementAction::All;
else
type = SoSelectionElementAction::None;
if (selaction->SelChange.Type == SelectionChanges::AddSelection) {
if (detail)
type = SoSelectionElementAction::Append;
else
type = SoSelectionElementAction::All;
}
else {
if (detail)
type = SoSelectionElementAction::Remove;
else
type = SoSelectionElementAction::None;
}
SoSelectionElementAction action(type);
action.setColor(this->colorSelection.getValue());
action.setElement(detail);
action.apply(vp->getRoot());
delete detail;
}
}
}
@ -335,7 +347,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action)
if (vpd && vpd->useNewSelectionModel() && vpd->isSelectable()) {
std::string documentName = vpd->getObject()->getDocument()->getName();
std::string objectName = vpd->getObject()->getNameInDocument();
std::string subElementName = vpd->getElement(pp);
std::string subElementName = vpd->getElement(pp ? pp->getDetail() : 0);
static char buf[513];
snprintf(buf,512,"Preselected: %s.%s.%s (%f,%f,%f)",documentName.c_str()
@ -378,7 +390,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action)
SoHighlightElementAction action;
action.setHighlighted(highlighted);
action.setColor(this->colorHighlight.getValue());
action.setElement(pp);
action.setElement(pp ? pp->getDetail() : 0);
action.apply(currenthighlight);
if (!highlighted) {
currenthighlight->unref();
@ -422,7 +434,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action)
SoSelectionElementAction::Type type = SoSelectionElementAction::None;
std::string documentName = vpd->getObject()->getDocument()->getName();
std::string objectName = vpd->getObject()->getNameInDocument();
std::string subElementName = vpd->getElement(pp);
std::string subElementName = vpd->getElement(pp ? pp->getDetail() : 0);
if (bCtrl) {
if (Gui::Selection().isSelected(documentName.c_str()
,objectName.c_str()
@ -495,7 +507,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action)
if (currenthighlight) {
SoSelectionElementAction action(type);
action.setColor(this->colorSelection.getValue());
action.setElement(pp);
action.setElement(pp ? pp->getDetail() : 0);
action.apply(currenthighlight);
this->touch();
}
@ -526,7 +538,7 @@ void SoHighlightElementAction::initClass()
SO_ACTION_ADD_METHOD(SoPointSet,callDoAction);
}
SoHighlightElementAction::SoHighlightElementAction () : _highlight(FALSE), _pp(0)
SoHighlightElementAction::SoHighlightElementAction () : _highlight(FALSE), _det(0)
{
SO_ACTION_CONSTRUCTOR(SoHighlightElementAction);
}
@ -565,14 +577,14 @@ const SbColor& SoHighlightElementAction::getColor() const
return this->_color;
}
void SoHighlightElementAction::setElement(const SoPickedPoint* pp)
void SoHighlightElementAction::setElement(const SoDetail* det)
{
this->_pp = pp;
this->_det = det;
}
const SoPickedPoint* SoHighlightElementAction::getElement() const
const SoDetail* SoHighlightElementAction::getElement() const
{
return this->_pp;
return this->_det;
}
// ---------------------------------------------------------------
@ -596,7 +608,7 @@ void SoSelectionElementAction::initClass()
SO_ACTION_ADD_METHOD(SoPointSet,callDoAction);
}
SoSelectionElementAction::SoSelectionElementAction (Type t) : _type(t), _select(FALSE), _pp(0)
SoSelectionElementAction::SoSelectionElementAction (Type t) : _type(t), _select(FALSE), _det(0)
{
SO_ACTION_CONSTRUCTOR(SoSelectionElementAction);
}
@ -631,12 +643,12 @@ const SbColor& SoSelectionElementAction::getColor() const
return this->_color;
}
void SoSelectionElementAction::setElement(const SoPickedPoint* pp)
void SoSelectionElementAction::setElement(const SoDetail* det)
{
this->_pp = pp;
this->_det = det;
}
const SoPickedPoint* SoSelectionElementAction::getElement() const
const SoDetail* SoSelectionElementAction::getElement() const
{
return this->_pp;
return this->_det;
}

View File

@ -43,6 +43,7 @@
class SoFullPath;
class SoPickedPoint;
class SoDetail;
namespace Gui {
@ -125,8 +126,8 @@ public:
SbBool isHighlighted() const;
void setColor(const SbColor&);
const SbColor& getColor() const;
void setElement(const SoPickedPoint*);
const SoPickedPoint* getElement() const;
void setElement(const SoDetail*);
const SoDetail* getElement() const;
static void initClass();
@ -139,7 +140,7 @@ private:
private:
SbBool _highlight;
SbColor _color;
const SoPickedPoint* _pp;
const SoDetail* _det;
};
/**
@ -158,8 +159,8 @@ public:
Type getType() const;
void setColor(const SbColor&);
const SbColor& getColor() const;
void setElement(const SoPickedPoint*);
const SoPickedPoint* getElement() const;
void setElement(const SoDetail*);
const SoDetail* getElement() const;
static void initClass();
@ -173,7 +174,7 @@ private:
Type _type;
SbBool _select;
SbColor _color;
const SoPickedPoint* _pp;
const SoDetail* _det;
};

View File

@ -2055,7 +2055,7 @@ SoPath * View3DInventorViewer::pickFilterCB(void *viewer, const SoPickedPoint *
{
ViewProvider* vp = static_cast<View3DInventorViewer*>(viewer)->getViewProviderByPath(pp->getPath());
if (vp && vp->useNewSelectionModel()) {
std::string e = vp->getElement(pp);
std::string e = vp->getElement(pp->getDetail());
vp->getSelectionShape(e.c_str());
static char buf[513];
snprintf(buf,512,"Hovered: %s (%f,%f,%f)"

View File

@ -944,7 +944,7 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args)
dict.setItem("Object",
Py::String(vpd->getObject()->getNameInDocument()));
dict.setItem("Component",
Py::String(vpd->getElement(Point)));
Py::String(vpd->getElement(Point->getDetail())));
// ok, found the node of interest
ret = dict;
}
@ -1017,7 +1017,7 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args)
dict.setItem("Object",
Py::String(vpd->getObject()->getNameInDocument()));
dict.setItem("Component",
Py::String(vpd->getElement(point)));
Py::String(vpd->getElement(point->getDetail())));
// ok, found the node of interest
list.append(dict);
}

View File

@ -40,6 +40,7 @@ class SoTransform;
class SbMatrix;
class SoEventCallback;
class SoPickedPoint;
class SoDetail;
class QString;
class QMenu;
class QObject;
@ -103,7 +104,8 @@ public:
/// indicates if the ViewProvider can be selected
virtual bool isSelectable(void) const {return true;}
/// return a hit element to the selection path or 0
virtual std::string getElement(const SoPickedPoint *) const { return std::string(); }
virtual std::string getElement(const SoDetail *) const { return std::string(); }
virtual SoDetail* getDetail(const char*) const { return 0; }
/// return the higlight lines for a given element or the whole shape
virtual std::vector<Base::Vector3d> getSelectionShape(const char* Element) const
{ return std::vector<Base::Vector3d>(); };

View File

@ -281,7 +281,7 @@ std::vector<App::DocumentObject*> ViewProviderPythonFeatureImp::claimChildren()
return children;
}
std::string ViewProviderPythonFeatureImp::getElement(const SoPickedPoint *pp) const
std::string ViewProviderPythonFeatureImp::getElement(const SoDetail *det) const
{
return "";
}

View File

@ -48,7 +48,7 @@ public:
// Returns the icon
QIcon getIcon() const;
std::vector<App::DocumentObject*> claimChildren() const;
std::string getElement(const SoPickedPoint *pp) const;
std::string getElement(const SoDetail *det) const;
std::vector<Base::Vector3d> getSelectionShape(const char* Element) const;
bool setEdit(int ModNum);
bool unsetEdit(int ModNum);
@ -125,8 +125,8 @@ public:
virtual bool useNewSelectionModel() const {
return ViewProviderT::useNewSelectionModel();
}
virtual std::string getElement(const SoPickedPoint *pp) const {
return ViewProviderT::getElement(pp);
virtual std::string getElement(const SoDetail *det) const {
return ViewProviderT::getElement(det);
}
virtual std::vector<Base::Vector3d> getSelectionShape(const char* Element) const {
return ViewProviderT::getSelectionShape(Element);

View File

@ -87,9 +87,8 @@ void SoBrepFaceSet::doAction(SoAction* action)
return;
}
const SoPickedPoint* pp = hlaction->getElement();
if (pp && pp->getDetail()) {
const SoDetail* detail = pp->getDetail();
const SoDetail* detail = hlaction->getElement();
if (detail) {
if (detail->isOfType(SoFaceDetail::getClassTypeId())) {
int index = static_cast<const SoFaceDetail*>(detail)->getPartIndex();
this->highlightIndex.setValue(index);
@ -118,10 +117,8 @@ void SoBrepFaceSet::doAction(SoAction* action)
return;
}
const SoPickedPoint* pp = selaction->getElement();
if (pp && pp->getDetail()) {
const SoDetail* detail = pp->getDetail();
const SoDetail* detail = selaction->getElement();
if (detail) {
if (!detail->isOfType(SoFaceDetail::getClassTypeId())) {
return;
}
@ -774,9 +771,8 @@ void SoBrepEdgeSet::doAction(SoAction* action)
this->hl.clear();
return;
}
const SoPickedPoint* pp = hlaction->getElement();
if (pp && pp->getDetail()) {
const SoDetail* detail = pp->getDetail();
const SoDetail* detail = hlaction->getElement();
if (detail) {
if (!detail->isOfType(SoLineDetail::getClassTypeId())) {
this->highlightIndex = -1;
this->hl.clear();
@ -824,9 +820,8 @@ void SoBrepEdgeSet::doAction(SoAction* action)
return;
}
const SoPickedPoint* pp = selaction->getElement();
if (pp && pp->getDetail()) {
const SoDetail* detail = pp->getDetail();
const SoDetail* detail = selaction->getElement();
if (detail) {
if (!detail->isOfType(SoLineDetail::getClassTypeId())) {
return;
}
@ -992,9 +987,8 @@ void SoBrepPointSet::doAction(SoAction* action)
this->highlightIndex = -1;
return;
}
const SoPickedPoint* pp = hlaction->getElement();
if (pp && pp->getDetail()) {
const SoDetail* detail = pp->getDetail();
const SoDetail* detail = hlaction->getElement();
if (detail) {
if (!detail->isOfType(SoPointDetail::getClassTypeId())) {
this->highlightIndex = -1;
return;
@ -1024,9 +1018,8 @@ void SoBrepPointSet::doAction(SoAction* action)
return;
}
const SoPickedPoint* pp = selaction->getElement();
if (pp && pp->getDetail()) {
const SoDetail* detail = pp->getDetail();
const SoDetail* detail = selaction->getElement();
if (detail) {
if (!detail->isOfType(SoPointDetail::getClassTypeId())) {
return;
}

View File

@ -371,10 +371,9 @@ std::vector<std::string> ViewProviderPartExt::getDisplayModes(void) const
return StrList;
}
std::string ViewProviderPartExt::getElement(const SoPickedPoint* pp) const
std::string ViewProviderPartExt::getElement(const SoDetail* detail) const
{
std::stringstream str;
const SoDetail* detail = pp->getDetail();
if (detail) {
if (detail->getTypeId() == SoFaceDetail::getClassTypeId()) {
const SoFaceDetail* face_detail = static_cast<const SoFaceDetail*>(detail);
@ -383,7 +382,7 @@ std::string ViewProviderPartExt::getElement(const SoPickedPoint* pp) const
}
else if (detail->getTypeId() == SoLineDetail::getClassTypeId()) {
const SoLineDetail* line_detail = static_cast<const SoLineDetail*>(detail);
int edge = line_detail->getPartIndex() + 1;
int edge = line_detail->getLineIndex() + 1;
str << "Edge" << edge;
}
else if (detail->getTypeId() == SoPointDetail::getClassTypeId()) {
@ -396,6 +395,35 @@ std::string ViewProviderPartExt::getElement(const SoPickedPoint* pp) const
return str.str();
}
SoDetail* ViewProviderPartExt::getDetail(const char* subelement) const
{
std::string element = subelement;
std::string::size_type pos = element.find_first_of("0123456789");
int index = -1;
if (pos != std::string::npos) {
index = std::atoi(element.substr(pos).c_str());
element = element.substr(0,pos);
}
SoDetail* detail = 0;
if (index < 0)
return detail;
if (element == "Face") {
detail = new SoFaceDetail();
static_cast<SoFaceDetail*>(detail)->setPartIndex(index - 1);
}
else if (element == "Edge") {
detail = new SoLineDetail();
static_cast<SoLineDetail*>(detail)->setLineIndex(index - 1);
}
else if (element == "Vertex") {
detail = new SoPointDetail();
static_cast<SoPointDetail*>(detail)->setCoordinateIndex(index + nodeset->startIndex.getValue() - 1);
}
return detail;
}
std::vector<Base::Vector3d> ViewProviderPartExt::getSelectionShape(const char* Element) const
{
return std::vector<Base::Vector3d>();

View File

@ -99,7 +99,8 @@ public:
/// indicates if the ViewProvider use the new Selection model
virtual bool useNewSelectionModel(void) const {return true;}
/// return a hit element to the selection path or 0
virtual std::string getElement(const SoPickedPoint*) const;
virtual std::string getElement(const SoDetail*) const;
virtual SoDetail* getDetail(const char*) const;
/// return the higlight lines for a given element or the whole shape
virtual std::vector<Base::Vector3d> getSelectionShape(const char* Element) const;
//@}