void IfReplacer::replaceMaterials(SoNode *sceneRoot, const SoType &typeToReplace) { // Find all nodes of the given type SoSearchAction sa; sa.setType(typeToReplace); sa.setInterest(SoSearchAction::ALL); sa.apply(sceneRoot); // Replace the tail of each path with a material. To do this, we // need to apply an SoCallbackAction to the path to gather the // material components. for (int i = 0; i < sa.getPaths().getLength(); i++) { // Cast the path to a full path, just in case SoFullPath *path = (SoFullPath *) sa.getPaths()[i]; ASSERT(path->getTail()->isOfType(typeToReplace)); // The path better have at least one group above the material if (path->getLength() < 2 || ! path->getNodeFromTail(1)->isOfType(SoGroup::getClassTypeId())) continue; // Create a material node that represents the material in // effect at the tail of the path SoMaterial *newMaterial = createMaterialForPath(path); newMaterial->ref(); // Replace the tail node with that material SoGroup *parent = (SoGroup *) path->getNodeFromTail(1); parent->replaceChild(path->getTail(), newMaterial); newMaterial->unref(); } }
void ViewProviderMeshDuplicatedPoints::attach(App::DocumentObject* pcFeat) { ViewProviderDocumentObject::attach( pcFeat ); SoGroup* pcPointRoot = new SoGroup(); pcDrawStyle->pointSize = 3; pcPointRoot->addChild(pcDrawStyle); // Draw points SoSeparator* pointsep = new SoSeparator; SoBaseColor * basecol = new SoBaseColor; basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); pointsep->addChild(basecol); pointsep->addChild(pcCoords); pointsep->addChild(pcPoints); pcPointRoot->addChild(pointsep); // Draw markers SoBaseColor * markcol = new SoBaseColor; markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); SoMarkerSet* marker = new SoMarkerSet; marker->markerIndex=SoMarkerSet::PLUS_7_7; pointsep->addChild(markcol); pointsep->addChild(marker); addDisplayMaskMode(pcPointRoot, "Point"); }
void ViewProviderMeshIndices::attach(App::DocumentObject* pcFeat) { ViewProviderDocumentObject::attach( pcFeat ); SoGroup* pcFaceRoot = new SoGroup(); SoDrawStyle* pcFlatStyle = new SoDrawStyle(); pcFlatStyle->style = SoDrawStyle::FILLED; pcFaceRoot->addChild(pcFlatStyle); SoShapeHints * flathints = new SoShapeHints; flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ; flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; pcFaceRoot->addChild(flathints); // Draw lines SoSeparator* linesep = new SoSeparator; SoBaseColor * basecol = new SoBaseColor; basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcFaces); pcFaceRoot->addChild(linesep); // Draw markers SoBaseColor * markcol = new SoBaseColor; markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); SoMarkerSet* marker = new SoMarkerSet; marker->markerIndex=SoMarkerSet::PLUS_7_7; linesep->addChild(markcol); linesep->addChild(marker); addDisplayMaskMode(pcFaceRoot, "Face"); }
void ViewProviderMeshSelfIntersections::attach(App::DocumentObject* pcFeat) { ViewProviderDocumentObject::attach( pcFeat ); SoGroup* pcLineRoot = new SoGroup(); pcDrawStyle->lineWidth = 3; pcLineRoot->addChild(pcDrawStyle); // Draw lines SoSeparator* linesep = new SoSeparator; SoBaseColor * basecol = new SoBaseColor; basecol->rgb.setValue( 1.0f, 0.5f, 0.0f ); linesep->addChild(basecol); linesep->addChild(pcCoords); linesep->addChild(pcLines); pcLineRoot->addChild(linesep); // Draw markers SoBaseColor * markcol = new SoBaseColor; markcol->rgb.setValue( 1.0f, 1.0f, 0.0f ); SoMarkerSet* marker = new SoMarkerSet; marker->markerIndex=SoMarkerSet::PLUS_7_7; linesep->addChild(markcol); linesep->addChild(marker); addDisplayMaskMode(pcLineRoot, "Line"); }
void SoUnknownNode::createFromIsA(SoMFString *isA) // //////////////////////////////////////////////////////////////////////// { for (int i = 0; i < isA->getNum(); i++) { SoType t = SoType::fromName((*isA)[i]); if (t.canCreateInstance() && t.isDerivedFrom(SoNode::getClassTypeId())) { SoNode *alternateRep = (SoNode *)t.createInstance(); alternateRep->ref(); #ifdef DEBUG if (alternateRep == NULL) { SoDebugError::post("SoUnknownNode::createFromIsA", "SoType.createInstance returned " "NULL (type %s)", t.getName().getString()); return; } #endif // Copy over all fields that are shared: int num = instanceFieldData->getNumFields(); for (int j=0; j<num; j++) { const SbName &fieldName = instanceFieldData->getFieldName(j); SoField *f = instanceFieldData->getField(this, j); // Don't copy over fields with default values: if (f->isDefault()) continue; SoField *nf = alternateRep->getField(fieldName); if (nf != NULL && nf->getTypeId() == f->getTypeId()) { nf->copyFrom(*f); if (f->isConnectedFromField()) { SoField *cf; f->getConnectedField(cf); nf->connectFrom(cf); } else if (f->isConnectedFromEngine()) { SoEngineOutput *eo; f->getConnectedEngine(eo); nf->connectFrom(eo); } } } // And if alternateRep is a group, copy over hidden // children: if (alternateRep->isOfType(SoGroup::getClassTypeId())) { SoGroup *g = (SoGroup *)alternateRep; for (int kid = 0; kid < hiddenChildren.getLength(); kid++) { g->addChild(hiddenChildren[kid]); } } addChild(alternateRep); return; } } }
void Document::slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) { //Base::Console().Log("Document::slotChangedObject() called\n"); ViewProvider* viewProvider = getViewProvider(&Obj); if (viewProvider) { try { viewProvider->update(&Prop); } catch(const Base::MemoryException& e) { Base::Console().Error("Memory exception in '%s' thrown: %s\n",Obj.getNameInDocument(),e.what()); } catch(Base::Exception& e){ e.ReportException(); } catch(const std::exception& e){ Base::Console().Error("C++ exception in '%s' thrown: %s\n",Obj.getNameInDocument(),e.what()); } catch (...) { Base::Console().Error("Cannot update representation for '%s'.\n", Obj.getNameInDocument()); } // check for children if(viewProvider->getChildRoot()) { std::vector<App::DocumentObject*> children = viewProvider->claimChildren3D(); SoGroup* childGroup = viewProvider->getChildRoot(); // size not the same -> build up the list new if(childGroup->getNumChildren() != children.size()){ childGroup->removeAllChildren(); for(std::vector<App::DocumentObject*>::iterator it=children.begin();it!=children.end();++it){ ViewProvider* ChildViewProvider = getViewProvider(*it); if(ChildViewProvider) { SoSeparator* childRootNode = ChildViewProvider->getRoot(); childGroup->addChild(childRootNode); // cycling to all views of the document to remove the viewprovider from the viewer itself for (std::list<Gui::BaseView*>::iterator vIt = d->baseViews.begin();vIt != d->baseViews.end();++vIt) { View3DInventor *activeView = dynamic_cast<View3DInventor *>(*vIt); if (activeView && viewProvider) { if (d->_pcInEdit == ChildViewProvider) resetEdit(); activeView->getViewer()->removeViewProvider(ChildViewProvider); } } } } } } if (viewProvider->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) signalChangedObject(static_cast<ViewProviderDocumentObject&>(*viewProvider), Prop); } // a property of an object has changed setModified(true); }
void ViewProviderInventorObject::attach(App::DocumentObject *pcObj) { ViewProviderDocumentObject::attach(pcObj); SoGroup* pcFileBuf = new SoGroup(); pcFileBuf->addChild(pcBuffer); pcFileBuf->addChild(pcFile); addDisplayMaskMode(pcFileBuf, "FileBuffer"); addDisplayMaskMode(pcBuffer, "Buffer"); addDisplayMaskMode(pcFile, "File"); }
SoCallbackAction::Response SoToVRMLActionP::push_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoToVRMLActionP * thisp = THISP(closure); SoSeparator * newsep = NEW_NODE(SoSeparator, node); SoGroup * prevgroup = THISP(closure)->get_current_tail(); prevgroup->addChild(newsep); thisp->vrmlpath->append(newsep); return SoCallbackAction::CONTINUE; }
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setCameraType(SoType type) { if(!getSoRenderManager()->getCamera()->isOfType(SoPerspectiveCamera::getClassTypeId()) && !getSoRenderManager()->getCamera()->isOfType(SoOrthographicCamera::getClassTypeId())) { Base::Console().Warning("Quarter::setCameraType", "Only SoPerspectiveCamera and SoOrthographicCamera is supported."); return; } SoType perspectivetype = SoPerspectiveCamera::getClassTypeId(); SbBool oldisperspective = getSoRenderManager()->getCamera()->getTypeId().isDerivedFrom(perspectivetype); SbBool newisperspective = type.isDerivedFrom(perspectivetype); if((oldisperspective && newisperspective) || (!oldisperspective && !newisperspective)) // Same old, same old.. return; SoCamera* currentcam = getSoRenderManager()->getCamera(); SoCamera* newcamera = (SoCamera*)type.createInstance(); // Transfer and convert values from one camera type to the other. if(newisperspective) { convertOrtho2Perspective((SoOrthographicCamera*)currentcam, (SoPerspectiveCamera*)newcamera); } else { convertPerspective2Ortho((SoPerspectiveCamera*)currentcam, (SoOrthographicCamera*)newcamera); } getSoRenderManager()->setCamera(newcamera); getSoEventManager()->setCamera(newcamera); //if the superscene has a camera we need to replace it too SoSeparator* superscene = (SoSeparator*) getSoRenderManager()->getSceneGraph(); SoSearchAction sa; sa.setInterest(SoSearchAction::FIRST); sa.setType(SoCamera::getClassTypeId()); sa.apply(superscene); if(sa.getPath()) { SoNode* node = sa.getPath()->getTail(); SoGroup* parent = (SoGroup*) sa.getPath()->getNodeFromTail(1); if(node && node->isOfType(SoCamera::getClassTypeId())) { parent->replaceChild(node, newcamera); } } };
void SceneModel::setNode(QModelIndex index, SoNode* node) { this->setData(index, QVariant(QString::fromAscii(node->getTypeId().getName()))); if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) { SoGroup *group = static_cast<SoGroup*>(node); // insert SoGroup icon this->insertColumns(0,1,index); this->insertRows(0,group->getNumChildren(), index); for (int i=0; i<group->getNumChildren();i++) { SoNode* child = group->getChild(i); setNode(this->index(i, 0, index), child); } } // insert icon }
void ViewProviderInventorObject::adjustSelectionNodes(SoNode* child, const char* docname, const char* objname) { if (child->getTypeId().isDerivedFrom(SoFCSelection::getClassTypeId())) { static_cast<SoFCSelection*>(child)->documentName = docname; static_cast<SoFCSelection*>(child)->objectName = objname; } else if (child->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) { SoGroup* group = static_cast<SoGroup*>(child); for (int i=0; i<group->getNumChildren(); i++) { SoNode* subchild = group->getChild(i); adjustSelectionNodes(subchild, docname, objname); } } }
ViewProviderPointMarker::ViewProviderPointMarker() { pCoords = new SoCoordinate3(); pCoords->ref(); pCoords->point.setNum(0); pMarker = new SoMarkerSet(); pMarker->markerIndex = SoMarkerSet::CROSS_9_9; pMarker->numPoints=0; pMarker->ref(); SoGroup* grp = new SoGroup(); grp->addChild(pCoords); grp->addChild(pMarker); addDisplayMaskMode(grp, "Base"); setDisplayMaskMode("Base"); }
int main(int, char **argv) { // Initialize Inventor. This returns a main window to use. // If unsuccessful, exit. HWND myWindow = SoWin::init("Water molecule"); // pass the app name if (myWindow == NULL) exit(1); // Make a scene containing a red cone SoGroup *waterMolecule = new SoGroup; // water molecule SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoGroup *oxygen = new SoGroup; // oxygen atom SoMaterial *redPlastic = new SoMaterial; SoSphere *sphere1 = new SoSphere; SoGroup *hydrogen1 = new SoGroup; // hydrogen atoms SoGroup *hydrogen2 = new SoGroup; SoTransform *hydrogenXform1 = new SoTransform; SoTransform *hydrogenXform2 = new SoTransform; SoMaterial *whitePlastic = new SoMaterial; SoSphere *sphere2 = new SoSphere; SoSphere *sphere3 = new SoSphere; // Set all field values for the oxygen atom redPlastic->ambientColor.setValue(1.0, 0.0, 0.0); redPlastic->diffuseColor.setValue(1.0, 0.0, 0.0); redPlastic->specularColor.setValue(0.5, 0.5, 0.5); redPlastic->shininess = 0.5; // Set all field values for the hydrogen atoms hydrogenXform1->scaleFactor.setValue(0.75, 0.75, 0.75); hydrogenXform1->translation.setValue(0.1, 1.2, 1.0); hydrogenXform2->translation.setValue(0.0, -3.2, 0.0); whitePlastic->ambientColor.setValue(1.0, 1.0, 1.0); whitePlastic->diffuseColor.setValue(1.0, 1.0, 1.0); whitePlastic->specularColor.setValue(0.5, 0.5, 0.5); whitePlastic->shininess = 0.5; // Create a hierarchy waterMolecule->ref(); waterMolecule->addChild(oxygen); waterMolecule->addChild(hydrogen1); waterMolecule->addChild(hydrogen2); oxygen->addChild(redPlastic); oxygen->addChild(sphere1); hydrogen1->addChild(hydrogenXform1); hydrogen1->addChild(whitePlastic); hydrogen1->addChild(sphere2); hydrogen2->addChild(hydrogenXform2); hydrogen2->addChild(sphere3); SoWinExaminerViewer *myRenderArea = new SoWinExaminerViewer(myWindow); // Make myCamera see everything. myCamera->viewAll(waterMolecule, myRenderArea->getViewportRegion()); // Put our scene in myRenderArea, change the title myRenderArea->setSceneGraph(waterMolecule); myRenderArea->setTitle("Water molecule"); myRenderArea->show(); SoWin::show(myWindow); // Display main window SoWin::mainLoop(); // Main Inventor event loop delete myRenderArea; waterMolecule->unref(); return 0; }
void SoXipMenu::onMenuChange() { mItemSeparator->removeAllChildren(); for( int i = 0; i < size(); ++ i ) { SoTranslation* offset = new SoTranslation; offset->translation.setValue( 0, getItem(i)->getHeight(), 0 ); SoGroup* itemGroup = new SoGroup; itemGroup->addChild( getItem(i) ); itemGroup->addChild( offset ); mItemSeparator->addChild( itemGroup ); } }
void removeNodes(SoGroup *root, SoType type) // ////////////////////////////////////////////////////////////// { SoSearchAction act; act.setInterest(SoSearchAction::ALL); act.setType(type); act.apply(root); SoPathList &paths = act.getPaths(); for (int i = 0; i < paths.getLength(); i++) { SoNode *kid = paths[i]->getTail(); paths[i]->pop(); SoGroup *parent = (SoGroup *)paths[i]->getTail(); parent->removeChild(kid); } }
SoGroup* TDragger::buildGeometry() { //this builds one leg in the Y+ direction because of default done direction. //the location anchor for shapes is the center of shape. SoGroup *root = new SoGroup(); //cylinder float cylinderHeight = 10.0; float cylinderRadius = 0.2f; SoSeparator *cylinderSeparator = new SoSeparator(); root->addChild(cylinderSeparator); SoTranslation *cylinderTranslation = new SoTranslation(); cylinderTranslation->translation.setValue(0.0, cylinderHeight / 2.0, 0.0); cylinderSeparator->addChild(cylinderTranslation); SoCylinder *cylinder = new SoCylinder(); cylinder->radius.setValue(cylinderRadius); cylinder->height.setValue(cylinderHeight); cylinderSeparator->addChild(cylinder); //cone float coneBottomRadius = 1.0; float coneHeight = 2.0; SoSeparator *coneSeparator = new SoSeparator(); root->addChild(coneSeparator); SoPickStyle *pickStyle = new SoPickStyle(); pickStyle->style.setValue(SoPickStyle::SHAPE); pickStyle->setOverride(TRUE); coneSeparator->addChild(pickStyle); SoTranslation *coneTranslation = new SoTranslation(); coneTranslation->translation.setValue(0.0, cylinderHeight + coneHeight / 2.0, 0.0); coneSeparator->addChild(coneTranslation); SoCone *cone = new SoCone(); cone->bottomRadius.setValue(coneBottomRadius); cone->height.setValue(coneHeight); coneSeparator->addChild(cone); return root; }
void Mesh2DView:: generateSceneGraph( bool /*bForce*/) { m_material->diffuseColor.setValue(obj->sbColour()); updateMaterial(); root->addChild(m_material); root->addChild(m_drawStyle); SoGroup *cache; if(obj->isCachedVisualisation()) { cache = obj->cachedVisualisation(); } else { cache = new SoGroup; WlzErrorNum errNum = WLZ_ERR_NONE; SoCoordinate3 * nodes; // nodes of the mesh SoIndexedFaceSet * faceset; // lines of the mesh nodes = Vertices2D(new SoCoordinate3, errNum); if(errNum == WLZ_ERR_NONE) { faceset = Faces2D(new SoIndexedFaceSet, errNum); } if( (errNum != WLZ_ERR_NONE) || (nodes == NULL) || (faceset == NULL)) { return ; } SoShapeHints *h1= new SoShapeHints; Q_ASSERT(h1); h1->vertexOrdering = SoShapeHints::CLOCKWISE; h1->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; cache->addChild(h1); cache->addChild(nodes); cache->addChild(faceset); obj->setVisualisation(cache); } root->addChild(cache); }
void SceneModel::setNode(QModelIndex index, SoNode* node) { this->setData(index, QVariant(QString::fromLatin1(node->getTypeId().getName()))); if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) { SoGroup *group = static_cast<SoGroup*>(node); // insert SoGroup icon this->insertColumns(0,2,index); this->insertRows(0,group->getNumChildren(), index); for (int i=0; i<group->getNumChildren();i++) { SoNode* child = group->getChild(i); setNode(this->index(i, 0, index), child); // See ViewProviderDocumentObject::updateData QByteArray name(child->getName()); name = QByteArray::fromPercentEncoding(name); this->setData(this->index(i, 1, index), QVariant(QString::fromUtf8(name))); } } // insert icon }
SoGroup * SoFile::copyChildren() const // //////////////////////////////////////////////////////////////////////// { // Create a new SoGroup with our children, and return a copy of // it. This will ensure that connections are copied properly. SoGroup *holder = new SoGroup; holder->ref(); for (int i = 0; i < children.getLength(); i++) holder->addChild(children[i]); SoGroup *result = (SoGroup *) holder->copy(TRUE); holder->unref(); return result; }
void SetupResultBoundingBox::go(ResultEntry *entry) { entry->boxSep = new SoSeparator(); entry->viewProvider->getRoot()->addChild(entry->boxSep); entry->boxSwitch = new SoSwitch(); entry->boxSep->addChild(entry->boxSwitch); SoGroup *group = new SoGroup(); entry->boxSwitch->addChild(group); entry->boxSwitch->whichChild.setValue(SO_SWITCH_NONE); SoDrawStyle *dStyle = new SoDrawStyle(); dStyle->style.setValue(SoDrawStyle::LINES); dStyle->linePattern.setValue(0xc0c0); group->addChild(dStyle); SoMaterial *material = new SoMaterial(); material->diffuseColor.setValue(255.0, 255.0, 255.0); material->ambientColor.setValue(255.0, 255.0, 255.0); group->addChild(material); Bnd_Box boundingBox; BRepBndLib::Add(entry->shape, boundingBox); Standard_Real xmin, ymin, zmin, xmax, ymax, zmax; boundingBox.Get(xmin, ymin, zmin, xmax, ymax, zmax); double xCenter, yCenter, zCenter; xCenter = (xmax - xmin)/2 + xmin; yCenter = (ymax - ymin)/2 + ymin; zCenter = (zmax - zmin)/2 + zmin; SbVec3f boundCenter(xCenter, yCenter, zCenter); Standard_Real x, y, z; entry->shape.Location().Transformation().TranslationPart().Coord(x, y, z); boundCenter -= SbVec3f(x, y, z); SoTransform *position = new SoTransform(); position->translation.setValue(boundCenter); group->addChild(position); SoCube *cube = new SoCube(); cube->width.setValue(xmax - xmin); cube->height.setValue(ymax - ymin); cube->depth.setValue(zmax - zmin); group->addChild(cube); }
SoMaterial * SoToVRMLActionP::find_or_create_material(void) { SoMaterial * mat = NULL; SoGroup * tail = this->get_current_tail(); int num = tail->getNumChildren(); while (--num >= 0 && mat == NULL) { SoNode * node = tail->getChild(num); if (node->isOfType(SoMaterial::getClassTypeId())) { mat = coin_assert_cast<SoMaterial*>(node); } } if (mat == NULL) { mat = new SoMaterial; tail->addChild(mat); } return mat; }
void MyExaminerViewer::Draw() { sp = new SoSeparator; sp->ref(); SoSphere *headSphere = new SoSphere; SoMaterial *bronze = new SoMaterial; bronze->ambientColor.setValue(0.33,0.22,0.27); bronze->diffuseColor.setValue(0.78,0.57,0.11); bronze->specularColor.setValue(0.99,0.94,0.81); bronze->shininess = 0.28; SoTransform *myTransform = new SoTransform; myTransform->translation.setValue(0.0,-1.0,0.0); SoGroup *head = new SoGroup; head->addChild(myTransform); head->addChild(bronze); head->addChild(headSphere); sp->addChild(head); }
SoCallbackAction::Response SoToVRMLActionP::vrmlextrusion_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoToVRMLActionP * thisp = THISP(closure); SoGroup * tail = thisp->get_current_tail(); const SoVRMLExtrusion * ext = coin_assert_cast<const SoVRMLExtrusion*>(node); SoShapeHints * sh = new SoShapeHints; sh->creaseAngle = ext->creaseAngle.getValue(); sh->vertexOrdering = ext->ccw.getValue() ? SoShapeHints::COUNTERCLOCKWISE : SoShapeHints::CLOCKWISE; sh->shapeType = ext->solid.getValue() ? SoShapeHints::SOLID : SoShapeHints::UNKNOWN_SHAPE_TYPE; sh->faceType = ext->convex.getValue() ? SoShapeHints::CONVEX : SoShapeHints::UNKNOWN_FACE_TYPE; tail->addChild(sh); thisp->init_gen(FALSE); return SoCallbackAction::CONTINUE; }
SoNode * replaceSeparators(SoNode *root) // ////////////////////////////////////////////////////////////// { // // if it's a group, make a new group and copy its // children over // if (root->isOfType(SoGroup::getClassTypeId())) { SoGroup *group = (SoGroup *) root; SoGroup *newGroup = (SoGroup *) group->getTypeId().createInstance(); newGroup->SoNode::copyContents(group, FALSE); int i; for (i=0; i<group->getNumChildren(); i++) { SoNode *child = replaceSeparators(group->getChild(i)); newGroup->addChild(child); } return newGroup; } // // if not a group, return the node // else return root; }
// creates a part of a scene-graph which is an arrow suitable for the decoration // of our SoJackDragger SoGroup *InvPlaneMover::makeArrow() { static float vertexPos[2][3] = { { 0.0f, 0.0f, 0.f }, { 0.0f, -0.7f, 0.0f } }; SoGroup *arrow = new SoGroup; SoLineSet *line = new SoLineSet; SoCoordinate3 *coords = new SoCoordinate3; coords->point.setValues(0, 2, vertexPos); arrow->addChild(coords); arrow->addChild(line); SoTranslation *transl = new SoTranslation; transl->translation.setValue(0.0f, -0.85f, 0.0f); arrow->addChild(transl); SoRotationXYZ *rot = new SoRotationXYZ; rot->angle = (float)M_PI; rot->axis = SoRotationXYZ::Z; arrow->addChild(rot); SoCone *tip = new SoCone; tip->bottomRadius = 0.1f; tip->height = 0.3f; arrow->addChild(tip); return arrow; }
void SoToVRMLActionP::init_gen(const SbBool color) { SbBool dotex = FALSE; SoGroup * tail = this->get_current_tail(); const int n = tail->getNumChildren(); for (int i = 0; i < n; i++) { if (tail->getChild(i)->isOfType(SoTexture2::getClassTypeId())) { dotex = TRUE; break; } } this->bsptree = new SbBSPTree; if (dotex) this->bsptreetex = new SbBSPTree; this->bsptreenormal = new SbBSPTree; this->coordidx = new SbList <int32_t>; this->normalidx = new SbList <int32_t>; if (dotex) this->texidx = new SbList <int32_t>; if (color) this->coloridx = new SbList <int32_t>; }
SoCallbackAction::Response SoToVRMLActionP::post_primitives_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoToVRMLActionP * thisp = THISP(closure); int n; SoGroup * tail = thisp->get_current_tail(); SoCoordinate3 * coord = new SoCoordinate3; coord->point.setValues(0, thisp->bsptree->numPoints(), thisp->bsptree->getPointsArrayPtr()); tail->addChild(coord); SoIndexedFaceSet * ifs = NEW_NODE(SoIndexedFaceSet, node); SoNormal * normal = new SoNormal; normal->vector.setValues(0, thisp->bsptreenormal->numPoints(), thisp->bsptreenormal->getPointsArrayPtr()); tail->addChild(normal); ifs->coordIndex.setValues(0, thisp->coordidx->getLength(), thisp->coordidx->getArrayPtr()); ifs->normalIndex.setValues(0, thisp->normalidx->getLength(), thisp->normalidx->getArrayPtr()); if (thisp->texidx) { SoTextureCoordinate2 * tex = new SoTextureCoordinate2; ifs->textureCoordIndex.setValues(0, thisp->texidx->getLength(), thisp->texidx->getArrayPtr()); tail->addChild(tex); n = thisp->bsptreetex->numPoints(); tex->point.setNum(n); SbVec2f * ptr = tex->point.startEditing(); for (int i = 0; i < n; i++) { SbVec3f p = thisp->bsptreetex->getPoint(i); ptr[i] = SbVec2f(p[0], p[1]); } tex->point.finishEditing(); } if (thisp->coloridx) { SoMaterialBinding * bind = new SoMaterialBinding; bind->value = SoMaterialBinding::PER_VERTEX_INDEXED; tail->addChild(bind); ifs->materialIndex.setValues(0, thisp->coloridx->getLength(), thisp->coloridx->getArrayPtr()); } tail->addChild(ifs); delete thisp->bsptree; thisp->bsptree = NULL; delete thisp->bsptreetex; thisp->bsptreetex = NULL; delete thisp->bsptreenormal; thisp->bsptreenormal = NULL; delete thisp->coordidx; thisp->coordidx = NULL; delete thisp->normalidx; thisp->normalidx = NULL; delete thisp->texidx; thisp->texidx = NULL; delete thisp->coloridx; thisp->coloridx = NULL; return SoCallbackAction::CONTINUE; }
SoCallbackAction::Response SoToVRMLActionP::vrmlpointset_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoToVRMLActionP * thisp = THISP(closure); const SoVRMLPointSet * oldps = coin_assert_cast<const SoVRMLPointSet*>(node); SoPointSet * ps = NEW_NODE(SoPointSet, node); SoGroup * tail = thisp->get_current_tail(); SoVRMLColor * color = coin_assert_cast<SoVRMLColor*>(oldps->color.getValue()); SoVRMLCoordinate * coord = coin_assert_cast<SoVRMLCoordinate*>(oldps->coord.getValue()); if (coord) { SbName name = coord->getName(); SoCoordinate3 * newcoord = coin_assert_cast<SoCoordinate3 *> ( thisp->search_for_node(thisp->vrmlpath->getHead(), name, SoCoordinate3::getClassTypeId()) ); if (!newcoord) { newcoord = new SoCoordinate3; newcoord->setName(name); newcoord->point.setValues(0, coord->point.getNum(), coord->point.getValues(0)); } tail->addChild(newcoord); } if (color) { SoMaterial * mat = thisp->find_or_create_material(); mat->diffuseColor.setValues(0, color->color.getNum(), color->color.getValues(0)); } tail->addChild(ps); return SoCallbackAction::CONTINUE; }
void SceneModel::setNode(QModelIndex index, SoNode* node) { this->setData(index, QVariant(QString::fromLatin1(node->getTypeId().getName()))); if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) { SoGroup *group = static_cast<SoGroup*>(node); // insert SoGroup icon this->insertColumns(0,2,index); this->insertRows(0,group->getNumChildren(), index); for (int i=0; i<group->getNumChildren();i++) { SoNode* child = group->getChild(i); setNode(this->index(i, 0, index), child); QHash<SoNode*, QString>::iterator it = nodeNames.find(child); if (it != nodeNames.end()) { this->setData(this->index(i, 1, index), QVariant(it.value())); } else { this->setData(this->index(i, 1, index), QVariant(QString::fromLatin1(child->getName()))); } } } // insert icon }
/*! Returns a subgraph with a deep copy of the children of this node. */ SoGroup * SoFile::copyChildren(void) const { SoGroup * tmproot = new SoGroup; tmproot->ref(); // Instead of individually copying our children one by one and // attaching to the new group node root, we use a temporary group // node to first *attach* our children to, and then copying the // root. This is done so any interconnections between sub-graphs are // also copied. const SoChildList * cl = this->children; for (int i = 0; i < cl->getLength(); i++) { tmproot->addChild(cl->operator[](i)); } SoNode * n = tmproot->copy(TRUE); tmproot->unref(); return (SoGroup *)n; }