fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Contrib / BackgroundLoader / OSGModelRequest.cpp
blobc455ea4cd01a3307e8e45b17627ab77c984e215f
1 // the general scene file loading handler
2 #include "OSGSceneFileHandler.h"
3 #include "OSGVerifyGraphOp.h"
5 #include "OSGModelRequest.h"
6 #include "OSGGraphOpSeq.h"
8 #include <iostream>
10 OSG_BEGIN_NAMESPACE
12 ModelRequest::ModelRequest(void) :
13 mParent (NULL ),
14 mModel (NULL ),
15 mFilename ( ),
16 pChangeList (NULL ),
17 bVerifyModel(true ),
18 szGraphOp ("default")
22 ModelRequest::~ModelRequest(void)
24 mParent = NULL;
25 mModel = NULL;
26 pChangeList = NULL;
29 std::string ModelRequest::getDescription(void)
31 return std::string("ModelRequest: ") + mFilename;
34 void ModelRequest::execute(void)
36 std::cout << "ModelRequest: loading model: " << mFilename << std::endl;
38 GraphOpSeqRefPtr pGraphOp = NULL;
40 if(szGraphOp.compare("none") == 0)
42 // leave it NULL
44 else if(szGraphOp.compare("default") == 0)
46 pGraphOp = SceneFileHandler::the()->getDefaultGraphOp();
48 else
50 pGraphOp = GraphOpSeq::create(szGraphOp);
53 fprintf(stderr, "Using graphop %p\n", static_cast<void *>(pGraphOp.get()));
55 mModel = SceneFileHandler::the()->read(mFilename.c_str(),
56 pGraphOp );
58 if(bVerifyModel == true)
60 std::cout << "verify model" << std::endl;
62 VerifyGraphOpRefPtr vop = VerifyGraphOp::create();
64 vop->setRepair (true);
65 vop->setVerbose(true);
67 vop->traverse(mModel.get());
70 commitChanges();
72 pChangeList->merge(*Thread::getCurrentChangeList());
74 clearChangeList();
77 void ModelRequest::sync(void)
79 if (mParent != NULL && mModel != NULL)
81 std::cout << "ModelRequest: adding model to scene: "
82 << mFilename
83 << std::endl;
85 mParent->addChild(mModel);
87 Thread::getCurrentChangeList()->merge(*pChangeList);
90 mCompleted = true;
93 void ModelRequest::setVerifyModel(bool bVal)
95 bVerifyModel = bVal;
98 void ModelRequest::setGraphOp(const std::string &szVal)
100 szGraphOp = szVal;
103 OSG_END_NAMESPACE