// // convenience method that removes callbacks before unregistering child // void SoCenterballDragger::removeChildDragger(const char *childname) { SoDragger * child = coin_assert_cast<SoDragger *>(this->getAnyPart(childname, FALSE)); child->removeStartCallback(SoCenterballDragger::kidStartCB, this); child->removeFinishCallback(SoCenterballDragger::kidFinishCB, this); this->unregisterChildDragger(child); }
int main (int argc, char** argv) { // Initialize Inventor and Win HWND myWindow = SoWin::init(argv[0]); if (myWindow == NULL) exit(1); // Knoten zum Selektieren der angehängten Objekte rootSelection = new SoSelection; rootSelection->ref(); rootSelection->addSelectionCallback(selectionCallback, NULL); rootSelection->addDeselectionCallback(deselectionCallback, NULL); SoSeparator *root = new SoSeparator; rootSelection->addChild(root); // This function contains our code fragment. root->addChild(make_brett()); SoWrapperKit *myWrapperKit = new SoWrapperKit; // Figur mit Wrapper verbinden root->addChild(myWrapperKit); myWrapperKit->setPart("contents", (make_brett())); myWrapperKit->set((char *)"transform { translation 0 0 0 }"); // create the manipulators SoHandleBoxManip *myHandleBox = new SoHandleBoxManip; myHandleBox->ref(); SoTranslate2Dragger *myTranslater = new SoTranslate2Dragger; // Get the draggers and add callbacks to them. Note // that you don't put callbacks on manipulators. You put // them on the draggers which handle events for them. SoDragger *myDragger; myDragger = myHandleBox->getDragger(); myDragger->addStartCallback(dragStartCallback); myDragger->addFinishCallback(dragFinishCallback); SoWinExaminerViewer *myViewer = new SoWinExaminerViewer(myWindow); myViewer->setSceneGraph(rootSelection); myViewer->setGLRenderAction(new SoBoxHighlightRenderAction); myViewer->setTitle("Schachbrett"); myViewer->show(); myViewer->viewAll(); SoWin::show(myWindow); SoWin::mainLoop(); return 0; }
bool ObjectSimpleViewer:: parseClipPlane( const QDomElement &element) { float distance=0; SbVec3f pos; SbVec3f normal; SbVec3f scale(1.0f, 1.0f, 1.0f); QDomNode child = element.firstChild(); while(!child.isNull()) { const QDomElement &element = child.toElement(); if(element.tagName() == "Distance") { distance = element.text().toFloat(); } else if(element.tagName() == "Position") { pos = parseSbVec3f(element); } else if(element.tagName() == "Normal") { normal = parseSbVec3f(element); } else if(element.tagName() == "Scalefactor") { scale = parseSbVec3f(element); } child = child.nextSibling(); } if(!m_clipPlaneManip) { //create at first use m_clipPlaneManip = new SoClipPlaneManip; m_clipPlaneManip->ref(); m_clipPlaneManip->plane.setValue(SbPlane(normal, distance)); m_clipPlaneManip->draggerPosition = pos; SoDragger *dragger = m_clipPlaneManip->getDragger(); if(dragger && dragger->isOfType(SoJackDragger::getClassTypeId())) { SoJackDragger *jd = (SoJackDragger*)dragger; jd->scaleFactor.setValue(scale); } } return(true); }
bool ViewProviderMirror::setEdit(int ModNum) { if (ModNum == ViewProvider::Default) { // get the properties from the mirror feature Part::Mirroring* mf = static_cast<Part::Mirroring*>(getObject()); Base::BoundBox3d bbox = mf->Shape.getBoundingBox(); float len = (float)bbox.CalcDiagonalLength(); Base::Vector3d base = mf->Base.getValue(); Base::Vector3d norm = mf->Normal.getValue(); Base::Vector3d cent = bbox.GetCenter(); base = cent.ProjToPlane(base, norm); // setup the graph for editing the mirror plane SoTransform* trans = new SoTransform; SbRotation rot(SbVec3f(0,0,1), SbVec3f(norm.x,norm.y,norm.z)); trans->rotation.setValue(rot); trans->translation.setValue(base.x,base.y,base.z); trans->center.setValue(0.0f,0.0f,0.0f); SoMaterial* color = new SoMaterial(); color->diffuseColor.setValue(0,0,1); color->transparency.setValue(0.5); SoCoordinate3* points = new SoCoordinate3(); points->point.setNum(4); points->point.set1Value(0, -len/2,-len/2,0); points->point.set1Value(1, len/2,-len/2,0); points->point.set1Value(2, len/2, len/2,0); points->point.set1Value(3, -len/2, len/2,0); SoFaceSet* face = new SoFaceSet(); pcEditNode->addChild(trans); pcEditNode->addChild(color); pcEditNode->addChild(points); pcEditNode->addChild(face); // Now we replace the SoTransform node by a manipulator // Note: Even SoCenterballManip inherits from SoTransform // we cannot use it directly (in above code) because the // translation and center fields are overridden. SoSearchAction sa; sa.setInterest(SoSearchAction::FIRST); sa.setSearchingAll(FALSE); sa.setNode(trans); sa.apply(pcEditNode); SoPath * path = sa.getPath(); if (path) { SoCenterballManip * manip = new SoCenterballManip; manip->replaceNode(path); SoDragger* dragger = manip->getDragger(); dragger->addStartCallback(dragStartCallback, this); dragger->addFinishCallback(dragFinishCallback, this); dragger->addMotionCallback(dragMotionCallback, this); } pcRoot->addChild(pcEditNode); } else { ViewProviderPart::setEdit(ModNum); } return true; }
bool ObjectSimpleViewer:: saveAsXml( QXmlStreamWriter *xmlWriter) { Q_ASSERT(xmlWriter); xmlWriter->writeTextElement("Title", windowTitle()); if(m_mixSlider) { xmlWriter->writeTextElement("Mix", QString("%1").arg(m_mixSlider->value())); } xmlWriter->writeStartElement("Geometry"); const QRect geom = parentWidget()->geometry(); xmlWriter->writeTextElement("X", QString("%1").arg(geom .x())); xmlWriter->writeTextElement("Y", QString("%1").arg(geom .y())); xmlWriter->writeTextElement("Width", QString("%1").arg(geom .width())); xmlWriter->writeTextElement("Height", QString("%1").arg(geom .height())); xmlWriter->writeEndElement(); if(m_clipPlaneManip) { xmlWriter->writeStartElement("ClipPlane"); SbPlane plane = m_clipPlaneManip->plane.getValue(); SbVec3f vec = plane.getNormal(); xmlWriter->writeStartElement("Normal"); xmlWriter->writeTextElement("X", QString("%1").arg(vec[0])); xmlWriter->writeTextElement("Y", QString("%1").arg(vec[1])); xmlWriter->writeTextElement("Z", QString("%1").arg(vec[2])); xmlWriter->writeEndElement(); xmlWriter->writeTextElement("Distance", QString("%1").arg(plane.getDistanceFromOrigin())); vec = m_clipPlaneManip->draggerPosition.getValue(); xmlWriter->writeStartElement("Position"); xmlWriter->writeTextElement("X", QString("%1").arg(vec[0])); xmlWriter->writeTextElement("Y", QString("%1").arg(vec[1])); xmlWriter->writeTextElement("Z", QString("%1").arg(vec[2])); xmlWriter->writeEndElement(); SoDragger *dragger = m_clipPlaneManip->getDragger(); if(dragger && dragger->isOfType(SoJackDragger::getClassTypeId())) { SoJackDragger *jd = (SoJackDragger*)dragger; vec = jd->scaleFactor.getValue(); xmlWriter->writeStartElement("Scalefactor"); xmlWriter->writeTextElement("X", QString("%1").arg(vec[0])); xmlWriter->writeTextElement("Y", QString("%1").arg(vec[1])); xmlWriter->writeTextElement("Z", QString("%1").arg(vec[2])); xmlWriter->writeEndElement(); } xmlWriter->writeTextElement("Distance", QString("%1").arg(plane.getDistanceFromOrigin())); xmlWriter->writeEndElement(); } for(int i = 0; i < views.size(); ++i) { views.at(i)->saveAsXml(xmlWriter); } return(true); }
void SoDragPointDragger::metaKeyChangeCB( void *, SoDragger *inDragger ) // //////////////////////////////////////////////////////////////////////// { SoDragPointDragger *dp = (SoDragPointDragger *) inDragger; SoHandleEventAction *ha = dp->getHandleEventAction(); // We care if the shift key is down for drawing feedback. const SoEvent *event = dp->getEvent(); dp->shftDown = event->wasShiftDown(); // Don't check for grabber yet. // CONTROL key press overrides if the grabber is a childDragger. // [1] We only respond to CONTROL key press events. if ( !SO_KEY_PRESS_EVENT(event, LEFT_CONTROL) && !SO_KEY_PRESS_EVENT(event, RIGHT_CONTROL)) return; //[2] Should we return? // Stay here if there's no grabber and the mouse is over us, // or over a surrogate part. // Stay here if we are the grabber. // Stay here if our currentDragger is grabbing events. // Return if anyone else is grabbing. SbBool takeIt = FALSE; if ( ha->getGrabber() == NULL ) { // grabber is NULL... const SoPickedPoint *p = ha->getPickedPoint(); if ( p && p->getPath()) { // Are we on the pickPath? // Or is the path a surrogate path for us or any draggers // contained within us? if ( p->getPath()->containsNode(dp) || dp->isPathSurrogateInMySubgraph(p->getPath()) ) takeIt = TRUE; } } else if ( ha->getGrabber() == dp ) takeIt = TRUE; else if ( ha->getGrabber() == dp->currentDragger ) takeIt = TRUE; else takeIt = FALSE; if ( !takeIt ) return; //[3] Now, switch the set of visible draggers... dp->showNextDraggerSet(); //[4] If a child is grabbing, release events and hand it all over to // the next one... SoDragger *oldDragger = dp->currentDragger; if (oldDragger) { // Ref the oldDragger. oldDragger->ref(); // Release the grabber. This will call grabEventsCleanUp() if // the grabber is a dragger. ha->releaseGrabber(); // If there was an oldDragger, // [a] select a new dragger to grab events. // [b] Set up a plane or line projector oriented like newDragger. // [c] Find out where current mouse position intersects that new // plane or line. The new gesture will continue from there. SoDragger *newDragger; SbVec3f projPt; SbLineProjector lp; SbPlaneProjector pp; lp.setViewVolume( dp->getViewVolume() ); pp.setViewVolume( dp->getViewVolume() ); lp.setWorkingSpace( dp->getLocalToWorldMatrix() ); pp.setWorkingSpace( dp->getLocalToWorldMatrix() ); if ( oldDragger == dp->xTranslator.getValue() ) { newDragger = (SoDragger *) dp->yTranslator.getValue(); lp.setLine( SbLine( SbVec3f(0,0,0), SbVec3f(0,1,0))); projPt = lp.project(dp->getNormalizedLocaterPosition()); } else if ( oldDragger == dp->yTranslator.getValue() ) { newDragger = (SoDragger *) dp->zTranslator.getValue(); lp.setLine( SbLine( SbVec3f(0,0,0), SbVec3f(0,0,1))); projPt = lp.project(dp->getNormalizedLocaterPosition()); } else if ( oldDragger == dp->zTranslator.getValue() ) { newDragger = (SoDragger *) dp->xTranslator.getValue(); lp.setLine( SbLine( SbVec3f(0,0,0), SbVec3f(1,0,0))); projPt = lp.project(dp->getNormalizedLocaterPosition()); } else if ( oldDragger == dp->yzTranslator.getValue() ) { newDragger = (SoDragger *) dp->xzTranslator.getValue(); pp.setPlane( SbPlane( SbVec3f(0,1,0), SbVec3f(0,0,0))); projPt = pp.project(dp->getNormalizedLocaterPosition()); } else if ( oldDragger == dp->xzTranslator.getValue() ) { newDragger = (SoDragger *) dp->xyTranslator.getValue(); pp.setPlane( SbPlane( SbVec3f(0,0,1), SbVec3f(0,0,0))); projPt = pp.project(dp->getNormalizedLocaterPosition()); } else if ( oldDragger == dp->xyTranslator.getValue() ) { newDragger = (SoDragger *) dp->yzTranslator.getValue(); pp.setPlane( SbPlane( SbVec3f(1,0,0), SbVec3f(0,0,0))); projPt = pp.project(dp->getNormalizedLocaterPosition()); } // unref oldDragger. We don't need it any more. oldDragger->unref(); // Give newDragger our handleEvent action. newDragger->setHandleEventAction(ha); // Cast the projPt into world space for the new starting point. dp->getLocalToWorldMatrix().multVecMatrix(projPt,projPt); newDragger->setStartingPoint( projPt ); // Give the newDragger a path to itself SoPath *pathToDragger; // We must ref() & unref() dpThisPath to dispose of it. SoPath *dpThisPath = dp->createPathToThis(); if (dpThisPath) dpThisPath->ref(); pathToDragger = dp->createPathToPart( dp->getPartString(newDragger), TRUE, dpThisPath ); if (dpThisPath) dpThisPath->unref(); if (pathToDragger) pathToDragger->ref(); newDragger->setTempPathToThis( pathToDragger ); if (pathToDragger) pathToDragger->unref(); // Give the newDragger our viewing information. newDragger->setViewVolume(dp->getViewVolume()); newDragger->setViewportRegion(dp->getViewportRegion()); // Set the grabber. This will call starting callbacks on the new // grabber, as well as it's registered parent, moi! ha->setGrabber( newDragger ); } //[5] set handled ha->setHandled(); }
// Doc in superclass. SbBool SoCenterballDragger::setUpConnections(SbBool onoff, SbBool doitalways) { if (!doitalways && this->connectionsSetUp == onoff) return onoff; int i; SbString str; if (onoff) { inherited::setUpConnections(onoff, doitalways); SoDragger *child; child = coin_assert_cast<SoDragger *>(this->getAnyPart("rotator", FALSE)); child->setPartAsDefault("rotator", "centerballRotator"); child->setPartAsDefault("rotatorActive", "centerballRotatorActive"); child->setPartAsDefault("feedback", new SoSeparator); child->setPartAsDefault("feedbackActive", new SoSeparator); this->addChildDragger(child); for (i = 0; i < 3; i++) { str.sprintf("%cRotator", 'X' + i); child = static_cast<SoDragger *>(this->getAnyPart(str.getString(), FALSE)); child->setPartAsDefault("rotator", "centerballStripe"); child->setPartAsDefault("rotatorActive", "centerballStripeActive"); child->setPartAsDefault("feedback", new SoSeparator); child->setPartAsDefault("feedbackActive", new SoSeparator); this->addChildDragger(child); } for (i = 0; i < 3; i++) { str.sprintf("%cCenterChanger", 'X' + i); child = coin_assert_cast<SoDragger *>(this->getAnyPart(str.getString(), FALSE)); child->setPartAsDefault("translator", "centerballCenterChanger"); child->setPartAsDefault("translatorActive", "centerballCenterChangerActive"); child->setPartAsDefault("xAxisFeedback", "centerballCenterXAxisFeedback"); child->setPartAsDefault("yAxisFeedback", "centerballCenterYAxisFeedback"); this->addChildDragger(child); } // Update dragger in case fields have changed values before connection SoCenterballDragger::fieldSensorCB(this, NULL); if (this->rotFieldSensor->getAttachedField() != &this->rotation) { this->rotFieldSensor->attach(&this->rotation); } if (this->centerFieldSensor->getAttachedField() != &this->center) { this->centerFieldSensor->attach(&this->center); } } else { this->removeChildDragger("rotator"); this->removeChildDragger("XRotator"); this->removeChildDragger("YRotator"); this->removeChildDragger("ZRotator"); this->removeChildDragger("XCenterChanger"); this->removeChildDragger("YCenterChanger"); this->removeChildDragger("ZCenterChanger"); if (this->rotFieldSensor->getAttachedField() != NULL) { this->rotFieldSensor->detach(); } if (this->centerFieldSensor->getAttachedField() != NULL) { this->centerFieldSensor->detach(); } inherited::setUpConnections(onoff, doitalways); } return !(this->connectionsSetUp = onoff); }