void SceneGraphTreeModel::addNode(NodeUnrecPtr parent,NodeUnrecPtr nodeToBeAdded) { UInt32 ChildIndex(parent->getNChildren()); NodeRefPtr(parent)->addChild(nodeToBeAdded); produceTreeNodesInserted(createPath(parent),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, nodeToBeAdded)); if(parent->getNChildren() == 1) { if(parent->getParent() != NULL) { std::vector<UInt32> childIndices; childIndices.push_back(parent->getParent()->findChild(parent)); std::vector<boost::any> ChildUserObjects; for(UInt32 i(0) ; i< childIndices.size() ; ++i) { ChildUserObjects.push_back(boost::any(NodeUnrecPtr(parent->getParent()->getChild(childIndices[i])))); } produceTreeNodesChanged(createPath(NodeUnrecPtr(parent->getParent())), childIndices, ChildUserObjects); } } }
UInt32 SceneGraphTreeModel::getChildCount(const boost::any& parent) const { try { NodeUnrecPtr TheNode = boost::any_cast<NodeUnrecPtr>(parent); if(TheNode != NULL) { return TheNode->getNChildren(); } else { return 0; } } catch(boost::bad_any_cast &ex) { SWARNING << "Bad any cast: " << ex.what() << std::endl; return 0; } }
boost::any SceneGraphTreeModel::getChild(const boost::any& parent, const UInt32& index) const { try { NodeUnrecPtr TheNode = boost::any_cast<NodeUnrecPtr>(parent); if(TheNode != NULL && TheNode->getNChildren() > index) { return boost::any(NodeUnrecPtr(TheNode->getChild(index))); } else { return boost::any(); } } catch(boost::bad_any_cast &ex) { SWARNING << "Bad any cast: " << ex.what() << std::endl; return boost::any(); } }
/* Insert one or more shallow copies of a block (created by DXFBlock as * Transform Group) into a layer (created by DXFLayer as MaterialGroup) or * another block. * \todo * Could there be a INSERT inside a block referring to another block which has * not been read yet? We then have to find a solution to enable deferred * instantiation of INSERT entities :-( */ DXFResult DXFInsert::endEntity(void) { NodeUnrecPtr ctrafoNodeP = NULL; // ComponentTransformUnrecPtr ctrafoCoreP = NULL; TransformUnrecPtr ctrafoCoreP = NULL; NodeUnrecPtr blockNodeP = NULL; Node *parentNodeP = getParentNode(); StringToNodePtrMap::iterator itr = _blocksMapP->find(_blockName); if (itr != _blocksMapP->end() && parentNodeP != NULL) { blockNodeP = itr->second; // TODO: check fetched INSERT Data for consistency! // Insert multiple times in a grid... Vec3f offset(0.0, 0.0, 0.0); for(Int16 column = 0; column < _columnCount; ++ column) { offset[0] = column * _columnSpacing; for(Int16 row = 0; row < _rowCount; ++ row) { offset[1] = row * _rowSpacing; // TODO: find out about DXF insert semantics! ctrafoNodeP = Node::create(); ctrafoCoreP = Transform::create(); #if 0 beginEditCP(ctrafoCoreP); #endif { if(_blockName == std::string("Rectangular Mullion - 64 x 128 rectangular-V1-Level 1")) { std::cout << blockNodeP->getNChildren() << std::endl; } OSG::TransformationMatrix<Real32> transMat; transMat.setIdentity(); transMat.setTranslate(_insertionPoint + offset); OSG::TransformationMatrix<Real32> rotMat; rotMat.setIdentity(); OSG::Quaternion rot(OSG::Vec3f(0,0,1),osgDegree2Rad(_rotationAngle)); rotMat.setRotate(rot); OSG::TransformationMatrix<Real32> scaleMat; scaleMat.setIdentity(); scaleMat.setScale(_scaleFactor); OSG::Vec3f vin(-40, 65, 0); OSG::Vec3f vout; transMat.mult(rotMat); transMat.mult(scaleMat); if(_extrusionDirection[2]<0) { transMat[0][0] *= -1.0; transMat[1][0] *= -1.0; transMat[2][0] *= -1.0; transMat[3][0] *= -1.0; } ctrafoCoreP->setMatrix(transMat); } #if 0 endEditCP(ctrafoCoreP); #endif #if 0 beginEditCP(ctrafoNodeP); #endif { ctrafoNodeP->setCore(ctrafoCoreP); #if 0 ctrafoNodeP->addChild(blockNodeP->clone()); #endif NodeUnrecPtr pClone = cloneTree(blockNodeP); ctrafoNodeP->addChild(pClone); } #if 0 endEditCP(ctrafoNodeP); #endif #if 0 beginEditCP(parentNodeP); #endif { parentNodeP->addChild(ctrafoNodeP); } #if 0 endEditCP(parentNodeP); #endif } } // Warn for details not implemented or assured yet! TODO: better // implement missing features! /*if(fabs(_rotationAngle) > Eps) FWARNING(("DXF Loader: before line %d: " "DXFInsert does not yet support ROTATION " "(group code 50). " "Most likely the graphics are incorrect!\n", DXFRecord::getLineNumber() ));*/ /*if(_scaleFactor != Vec3f(1.0,1.0,1.0)) FWARNING(("DXF Loader: before line %d: " "DXFInsert may not interpret SCALING " "(group codes 41, 42, 43) correctly." "Graphics may be incorrect!\n", DXFRecord::getLineNumber() ));*/ if(_columnCount != 1 || _rowCount != 1) FWARNING(("DXF Loader: before line %d: " "DXFInsert may not interpret REPEATED INSERTION " "(group codes 70, 71, 44, 45) correctly." "Graphics may be incorrect!\n", DXFRecord::getLineNumber() )); } else { if(itr == _blocksMapP->end()) FWARNING(("DXF Loader: before line %d (inside %s section): " "BLOCK '%s' to be inserted not found!\n", DXFRecord::getLineNumber(), _parent->getEntityTypeName(), _blockName.c_str() )); if(parentNodeP == NULL) FWARNING(("DXF Loader: before line %d (inside %s section): " "layer %s to be inserted to not found!\n", DXFRecord::getLineNumber(), _parent->getEntityTypeName(), _layerName.c_str() )); } //set back to default value; _insertionPoint.setNull(), _scaleFactor[0]=_scaleFactor[1]=_scaleFactor[2]=1.0; _rotationAngle=0.0; _columnCount=1; _rowCount=1; _columnSpacing=0.0; _rowSpacing=0.0; _extrusionDirection[0]=0; _extrusionDirection[1]=0; _extrusionDirection[2]=1; return DXFStateContinue; }