ReadContentDefinition/ReadContentDefinition.cpp

This sample shows how to read meta data based on the new content definition (DWFToolkit::DWFPackageReader DWFToolkit::DWFContentManager)

00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 
00023 #include <iomanip>
00024 #include <iostream>
00025 using namespace std;
00026 
00027 #include "dwfcore/File.h"
00028 #include "dwfcore/String.h"
00029 using namespace DWFCore;
00030 
00031 #include "dwf/package/Constants.h"
00032 #include "dwf/package/Manifest.h"
00033 #include "dwf/package/GlobalSection.h"
00034 #include "dwf/package/ContentManager.h"
00035 #include "dwf/package/reader/PackageReader.h"
00036 using namespace DWFToolkit;
00037 
00038 
00039 #ifdef  _DWFCORE_WIN32_SYSTEM
00040 #include <crtdbg.h>
00041 #endif
00042 
00043 
00044 const DWFString zMinIndent( L"    " );
00045 
00047 //
00048 //  declarations
00049 //
00050 
00051 void printTypeInfo( DWFPackageReader::tPackageInfo& tInfo );
00052 
00053 void getObjectInfoString( DWFObject* pObject, int nDepth, DWFString& zOut );
00054 void getChildObjectInfo( DWFObject* pObject, int nDepth, DWFString& zOut );
00055 
00056 void getPropertyInfo( DWFPropertyContainer* pContainer, int nDepth, DWFString& zOut );
00057 void getGlobalContentInfo( DWFContent* pContent, DWFString& zOut );
00058 void getContentInstances( DWFContent* pContent, DWFString& zOut );
00059 
00060 //
00061 //  Functions for interactive queries
00062 //
00063 void doPropertyTest( DWFContent* pContent );
00064 bool performPropertyQueries( DWFContentElement* pElem );
00065 
00067 //
00068 //  main
00069 //
00070 int main(int argc, char* argv[])
00071 {
00072 #ifdef  _DWFCORE_WIN32_SYSTEM
00073     //
00074     // Enable memory leak reporting in Debug mode under Win32.
00075     //
00076     int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
00077     // Turn on leak-checking bit
00078     tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
00079     // Turn off CRT block checking bit
00080     tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
00081     // Set flag to the new value
00082     _CrtSetDbgFlag( tmpFlag );
00083 
00084     // For mem leak debugging...
00085     /*
00086     long foo = 8217;
00087     _CrtSetBreakAlloc(foo);
00088     */
00089 #endif
00090 
00091     if (argc < 2)
00092     {
00093         wcout << L"Usage:" << argv[0] << L" file.dwf [-q]" << endl;
00094         wcout << L"-q is used to get into interactive mode to query specific objects" << endl;
00095         return ( 0 );
00096     }
00097 
00098     try
00099     {
00100         wcout << L"Reading package: " << argv[1] << endl;
00101 
00102         DWFFile oDWF( argv[1] );
00103         DWFPackageReader oReader( oDWF );
00104 
00105         DWFPackageReader::tPackageInfo tInfo;
00106         oReader.getPackageInfo( tInfo );
00107 
00108         printTypeInfo( tInfo );
00109 
00111 
00112         //
00113         //  Read manifest - this will create/read the manifest, and also create the content manager
00114         //
00115         DWFManifest& rManifest = oReader.getManifest();
00116 
00117         DWFContentManager* pContentManager = rManifest.getContentManager();
00118         DWFContent* pContent = pContentManager->getContent();
00119 
00120         //
00121         //  This piece is critical - the content still hasn't been loaded. 
00122         //  The call only loads the global information. To get section specific information loaded into the content
00123         //  you need to call DWFSection::getContentDefinition, a few lines later.
00124         //
00125         pContent->load();
00126 
00127         //
00128         //  Print out some of the global content information
00129         //
00130         DWFString zOut;
00131         getGlobalContentInfo( pContent, zOut );
00132         wcout << (const wchar_t*) zOut << endl;
00133 
00135 
00136         zOut.assign( L"" );
00137 
00138         //
00139         //  Now get sections, for each section find all section content resources 
00140         //  and load them.
00141         //
00142         DWFSection* pSection = NULL;
00143         DWFManifest::SectionIterator* piSections = rManifest.getSections();
00144         if (piSections)
00145         {
00146             for (; piSections->valid(); piSections->next())
00147             {
00148                 pSection = piSections->get();
00149                 pSection->readDescriptor();
00150 
00151                 //
00152                 //  This is NOT creating NEW contents - it loading one that was created during the manifest
00153                 //  loading process. Do not delete the content pointer here. In most cases there will be
00154                 //  only one content.
00155                 //
00156                 DWFContent::tIterator* piContent = pSection->getContentDefinition();
00157                 if (piContent)
00158                 {
00159                     for (; piContent->valid(); piContent->next())
00160                     {
00161                         DWFContent* pSectionContent = piContent->get();
00162 
00163                         if (pSectionContent == pContent)
00164                         {
00165                             zOut.assign( L"The section returned the global content we were looking at above\n\n" );
00166                         }
00167 
00168                         getContentInstances( pSectionContent, zOut );
00169 
00170                     }
00171                     DWFCORE_FREE_OBJECT( piContent );
00172                 }
00173             }
00174             if (zOut.chars()>0)
00175             {
00176                 wcout << (const wchar_t*) zOut << "\n" << endl;
00177             }
00178             else
00179             {
00180                 wcout << L"No instances were found.\n" << endl;
00181             }
00182 
00183             DWFCORE_FREE_OBJECT( piSections );
00184         }
00185 
00187         
00188         zOut.assign( L"" );
00189 
00190         if (argc>2 && argv[2][0]=='-' && argv[2][1]=='q')
00191         {
00192             doPropertyTest( pContent );
00193         }
00194 
00195         wcout << L"\nDONE\n";
00196     }
00197     catch (DWFException& ex)
00198     {
00199         wcout << ex.type() << endl;
00200         wcout << ex.message() << endl;
00201         wcout << ex.function() << endl;
00202         wcout << ex.file() << endl;
00203         wcout << ex.line() << endl;
00204     }
00205 
00206         return 0;
00207 }
00208 
00210 //
00211 // function definitions
00212 //
00213 
00214 std::wostream& operator<<( std::wostream& wos, const DWFString& zString )
00215 {
00216     if (zString.chars())
00217     {
00218         wos << (const wchar_t*)zString;
00219     }
00220     return wos;
00221 }
00222 
00223 DWFString getLine()
00224 {
00225     wcin.clear();
00226     wchar_t szIdentifier[256] = {0};
00227     if (wcin.peek()==10)
00228     {
00229         wcin.get();
00230     }
00231     wcin.getline( szIdentifier, 255 );
00232     return DWFString( szIdentifier );
00233 }
00234 
00235 #define ZOUTLABEL( pElem )  zOut.append( pElem->getLabel().chars()>0 ? pElem->getLabel() : pElem->id() );
00236 
00237 
00238 void printTypeInfo( DWFPackageReader::tPackageInfo& tInfo )
00239 {
00240     if (tInfo.eType != DWFPackageReader::eDWFPackage)
00241     {
00242         cout << "File is not a DWF package ";
00243         if (tInfo.eType == DWFPackageReader::eW2DStream)
00244         {
00245             cout << "[W2D Stream]";
00246         }
00247         else if (tInfo.eType == DWFPackageReader::eDWFStream)
00248         {
00249             cout << "[DWF Stream (<6.0)]";
00250         } 
00251         else if (tInfo.eType == DWFPackageReader::eZIPFile)
00252         {
00253             cout << "[ZIP Archive]";
00254         }
00255         else
00256         {
00257             cout << "[Unknown]";
00258         }
00259         cout << endl;
00260         exit( 0 );
00261     }
00262 
00263     cout << setprecision(2) << "DWF Package version [" << (float)(tInfo.nVersion)/100.0f << "]\n" << endl;
00264 }
00265 
00266 void getObjectInfoString( DWFObject* pObject, int nDepth, DWFString& zOut )
00267 {
00268     for (int i=0; i<nDepth; i++)
00269     {
00270         zOut.append( zMinIndent );   // Two space indentation
00271     }
00272     zOut.append( L"Object: " );
00273     ZOUTLABEL( pObject );
00274     zOut.append( L" - " );
00275     zOut.append( pObject->id() );
00276     zOut.append( L" : Entity: " );
00277     DWFEntity* pEntity = pObject->getEntity();
00278     ZOUTLABEL( pEntity );
00279     zOut.append( L"\n" );
00280 
00281     getPropertyInfo( pObject, nDepth, zOut );
00282 }
00283 
00284 void getChildObjectInfo( DWFObject* pObject, int nDepth, DWFString& zOut )
00285 {
00286     getObjectInfoString( pObject, nDepth, zOut );
00287 
00288     DWFObject::tIterator* piChild = pObject->getChildren();
00289     if (piChild)
00290     {
00291         for (; piChild->valid(); piChild->next())
00292         {
00293             getChildObjectInfo( piChild->get(), nDepth+1, zOut );
00294         }
00295         DWFCORE_FREE_OBJECT( piChild );
00296     }
00297 }
00298 
00299 void getPropertyInfo( DWFPropertyContainer* pContainer, int nDepth, DWFString& zOut )
00300 {
00301     {
00302         //
00303         // This code doesn't do anything useful. It's only here to help detect memory leaks.
00304         // Users of this sample should ignore it.
00305         DWFProperty::tMap::Iterator *piter = pContainer->getProperties();
00306         DWFCORE_FREE_OBJECT( piter );
00307     }
00308 
00309     DWFString zIndent;
00310     for (int i=0; i<nDepth; i++)
00311     {
00312         zIndent.append( zMinIndent );   // Two space indentation
00313     }
00314 
00315     //
00316     //  The type of container
00317     //
00318     if (dynamic_cast<DWFContentElement*>(pContainer))
00319     {
00320         //zOut.append( zIndent );
00321         //zOut.append( L"CE:\n" );
00322     }
00323     else
00324     {
00325         DWFPropertySet* pSet = dynamic_cast<DWFPropertySet*>(pContainer);
00326         if (pSet)
00327         {
00328             zOut.append( zIndent );
00329             zOut.append( L"PS:" );
00330             ZOUTLABEL( pSet );
00331             zOut.append( L"\n" );
00332         }
00333         else
00334         {
00335             zOut.append( zIndent );
00336             zOut.append( L"PC:" );
00337             zOut.append( pContainer->id() );
00338             zOut.append( L"\n" );
00339         }
00340     }
00341 
00342     DWFProperty::tIterator* piProperty = pContainer->getPropertiesInOrder();
00343     if (piProperty)
00344     {
00345         for (; piProperty->valid(); piProperty->next())
00346         {
00347             DWFProperty* pProperty = piProperty->get();
00348 
00349             zOut.append( zIndent );
00350             zOut.append( L"Property: (" );
00351             zOut.append( pProperty->name() );
00352             zOut.append( L" , " );
00353             zOut.append( pProperty->value() );
00354             if (pProperty->category().chars()>0)
00355             {
00356                 zOut.append( L" , " );
00357                 zOut.append( pProperty->category() );
00358             }
00359             zOut.append( L" )\n" );
00360         }
00361         DWFCORE_FREE_OBJECT( piProperty );
00362     }
00363 
00364     DWFPropertyContainer::tList oContainers;
00365     pContainer->getReferencedPropertyContainers( oContainers );
00366     if (oContainers.size()>0)
00367     {
00368         zOut.append( zIndent );
00369         zOut.append( L"Refs: " );
00370         DWFPropertyContainer::tList::iterator iCont = oContainers.begin();
00371         for (; iCont != oContainers.end(); ++iCont)
00372         {
00373             zOut.append( (*iCont)->id() );
00374             zOut.append( L" " );
00375         }
00376         zOut.append( L"\n" );
00377     }
00378 
00379     oContainers.clear();
00380     pContainer->getOwnedPropertyContainers( oContainers );
00381     if (oContainers.size()>0)
00382     {
00383         DWFPropertyContainer::tList::iterator iCont = oContainers.begin();
00384         for (; iCont != oContainers.end(); ++iCont)
00385         {
00386             getPropertyInfo( *iCont, nDepth+1, zOut );
00387         }
00388     }
00389 }
00390 
00391 void getGlobalContentInfo( DWFContent* pContent, DWFString& zOut )
00392 {
00393     //
00394     // Get shared property set information
00395     //
00396     zOut.append( "[SHARED PROPERTY SETS]\n" );
00397     DWFPropertySet::tMap::Iterator* piSet = pContent->getSharedPropertySets();
00398     if (piSet)
00399     {
00400         if (piSet->valid())
00401         {
00402             for (; piSet->valid(); piSet->next())
00403             {
00404                 DWFPropertySet* pSet = piSet->value();
00405 
00406                 if (pSet)
00407                 {
00408                     zOut.append( L"PropertySet: " );
00409                     zOut.append( pSet->getLabel().chars()>0 ? pSet->getLabel() : pSet->id() );
00410                     zOut.append( "   Closed: " );
00411                     zOut.append( (pSet->isClosed()?"true":"false") );
00412                     if (pSet->getSchemaID().chars())
00413                     {
00414                         zOut.append( "  SchemaID: " );
00415                         zOut.append( pSet->getSchemaID() );
00416                     }
00417                     if (pSet->getSetID().chars())
00418                     {
00419                         zOut.append( "  SetID: " );
00420                         zOut.append( pSet->getSetID() );
00421                     }
00422                     zOut.append( L"\n" );
00423                     getPropertyInfo( pSet, 0, zOut );
00424                 }
00425             }
00426             zOut.append( L"\n" );
00427         }
00428         else
00429         {
00430             zOut.append( L"None\n\n" );
00431         }
00432         DWFCORE_FREE_OBJECT( piSet );
00433     }
00434     else
00435     {
00436         zOut.append( L"None\n\n" );
00437     }
00438 
00439     //
00440     // Get class information
00441     //
00442     zOut.append( "[CLASSES]\n" );
00443     DWFClass::tMap::Iterator* piClass = pContent->getClasses();
00444     if (piClass)
00445     {
00446         if (piClass->valid())
00447         {
00448             for (; piClass->valid(); piClass->next())
00449             {
00450                 DWFClass* pClass = piClass->value();
00451 
00452                 if (pClass)
00453                 {
00454                     zOut.append( L"Class: " );
00455                     ZOUTLABEL( pClass );
00456                     zOut.append( L"\n" );
00457 
00458                     DWFEntity::tIterator* piEntity = pContent->findEntitiesByClass( pClass );
00459                     if (piEntity)
00460                     {
00461                         if (piEntity->valid())
00462                         {
00463                             zOut.append( "Referring entities: ");
00464                             for (; piEntity->valid(); piEntity->next())
00465                             {
00466                                 DWFEntity* pEntity = piEntity->get();
00467                                 ZOUTLABEL( pEntity );
00468                                 zOut.append( " " );
00469                             }
00470                             zOut.append( "\n" );
00471                         }
00472                         DWFCORE_FREE_OBJECT( piEntity );
00473                     }
00474 
00475                     getPropertyInfo( pClass, 0, zOut );
00476                 }
00477             }
00478             zOut.append( L"\n" );
00479         }
00480         else
00481         {
00482             zOut.append( L"None\n\n" );
00483         }
00484         DWFCORE_FREE_OBJECT( piClass );
00485     }
00486     else
00487     {
00488         zOut.append( L"None\n\n" );
00489     }
00490 
00491     //
00492     // Get feature information
00493     //
00494     zOut.append( "[FEATURES]\n" );
00495     DWFFeature::tMap::Iterator* piFeature = pContent->getFeatures();
00496     if (piFeature)
00497     {
00498         if (piFeature->valid())
00499         {
00500             for (; piFeature->valid(); piFeature->next())
00501             {
00502                 DWFFeature* pFeature = piFeature->value();
00503 
00504                 if (pFeature)
00505                 {
00506                     zOut.append( L"Feature: " );
00507                     ZOUTLABEL( pFeature );
00508                     zOut.append( L"\n" );
00509                     getPropertyInfo( pFeature, 0, zOut );
00510                 }
00511             }
00512             zOut.append( L"\n" );
00513         }
00514         else
00515         {
00516             zOut.append( L"None\n\n" );
00517         }
00518         DWFCORE_FREE_OBJECT( piFeature );
00519     }
00520     else
00521     {
00522         zOut.append( L"None\n\n" );
00523     }
00524 
00525     //
00526     // Get entity information
00527     //
00528     zOut.append( "[ENTITIES]\n" );
00529     DWFEntity::tMap::Iterator* piEntity = pContent->getEntities();
00530     if (piEntity)
00531     {
00532         if (piEntity->valid())
00533         {
00534             for (; piEntity->valid(); piEntity->next())
00535             {
00536                 DWFEntity* pEntity = piEntity->value();
00537 
00538                 if (pEntity)
00539                 {
00540                     zOut.append( L"Entity: " );
00541                     ZOUTLABEL( pEntity );
00542                     zOut.append( L" - " );
00543                     zOut.append( pEntity->id() );
00544                     zOut.append( L"\n" );
00545 
00546                     DWFObject::tIterator* piObject = pContent->findObjectsByEntity( pEntity );
00547                     if (piObject)
00548                     {
00549                         if (piObject->valid())
00550                         {
00551                             zOut.append( "Rendering objects: ");
00552                             for (; piObject->valid(); piObject->next())
00553                             {
00554                                 DWFObject* pObject = piObject->get();
00555                                 ZOUTLABEL( pObject );
00556                                 zOut.append( " " );
00557                             }
00558                             zOut.append( "\n" );
00559                         }
00560                         DWFCORE_FREE_OBJECT( piObject );
00561                     }
00562 
00563                     getPropertyInfo( pEntity, 0, zOut );
00564                 }
00565             }
00566             zOut.append( L"\n" );
00567         }
00568         else
00569         {
00570             zOut.append( L"None\n\n" );
00571         }
00572         DWFCORE_FREE_OBJECT( piEntity );
00573     }
00574     else
00575     {
00576         zOut.append( L"None\n\n" );
00577     }
00578 
00579     //
00580     // Get object information
00581     //
00582     zOut.append( "[OBJECTS]\n" );
00583     DWFObject::tMap::Iterator* piObject = pContent->getObjects();
00584     if (piObject)
00585     {
00586         if (piObject->valid())
00587         {
00588             int nObjectDepth = 0;
00589             for (; piObject->valid(); piObject->next())
00590             {
00591                 DWFObject* pObject = piObject->value();
00592 
00593                 if (pObject && pObject->getParent() == NULL)
00594                 {
00595                     getObjectInfoString( pObject, nObjectDepth, zOut );
00596                 }
00597 
00598                 DWFObject::tIterator* piChild = pObject->getChildren();
00599                 if (piChild)
00600                 {
00601                     for (; piChild->valid(); piChild->next())
00602                     {
00603                         getChildObjectInfo( piChild->get(), nObjectDepth+1, zOut );
00604                     }
00605                     DWFCORE_FREE_OBJECT( piChild );
00606                 }
00607             }
00608             zOut.append( L"\n" );
00609         }
00610         else
00611         {
00612             zOut.append( L"None\n\n" );
00613         }
00614         DWFCORE_FREE_OBJECT( piObject );
00615     }
00616     else
00617     {
00618         zOut.append( L"None\n\n" );
00619     }
00620 
00621     //
00622     // Get group information
00623     //
00624     zOut.append( "[GROUPS]\n" );
00625     DWFGroup::tMap::Iterator* piGroup = pContent->getGroups();
00626     if (piGroup)
00627     {
00628         if (piGroup->valid())
00629         {
00630             for (; piGroup->valid(); piGroup->next())
00631             {
00632                 DWFGroup* pGroup = piGroup->value();
00633 
00634                 if (pGroup)
00635                 {
00636                     zOut.append( L"Group: " );
00637                     zOut.append( pGroup->getLabel().chars()>0 ? pGroup->getLabel() : pGroup->id() );
00638                     zOut.append( L"\n" );
00639                     getPropertyInfo( pGroup, 0, zOut );
00640                 }
00641             }
00642             zOut.append( L"\n" );
00643         }
00644         else
00645         {
00646             zOut.append( L"None\n\n" );
00647         }
00648         DWFCORE_FREE_OBJECT( piGroup );
00649     }
00650     else
00651     {
00652         zOut.append( L"None\n\n" );
00653     }
00654 }
00655 
00656 void getContentInstances( DWFContent* pContent, DWFString& zOut )
00657 {
00658     zOut.append( "[INSTANCES]\n" );
00659     DWFInstance::tMap::Iterator* piInstance = pContent->getInstances();
00660     if (piInstance)
00661     {
00662         if (piInstance->valid())
00663         {
00664             for (; piInstance->valid(); piInstance->next())
00665             {
00666                 DWFInstance* pInstance = piInstance->value();
00667 
00668                 if (pInstance)
00669                 {
00670                     zOut.append( L"Instance: Renders " );
00671                     
00672                     DWFRenderable* pRendered = pInstance->getRenderedElement();
00673                     if (pRendered->getLabel().chars()>0)
00674                     {
00675                         zOut.append( pRendered->getLabel() );
00676                     }
00677                     else
00678                     {
00679                         zOut.append( pRendered->id() );
00680                     }
00681 
00682                     zOut.append( (pInstance->getVisibility() ? " : visible" : " : hidden") );
00683                     zOut.append( (pInstance->getTransparency() ? " : transparent" : " : opaque") );
00684                     zOut.append( L"\n" );
00685                 }
00686             }
00687             zOut.append( L"\n" );
00688         }
00689         else
00690         {
00691             zOut.append( L"None\n\n" );
00692         }
00693         DWFCORE_FREE_OBJECT( piInstance );
00694     }
00695     else
00696     {
00697         zOut.append( L"None\n\n" );
00698     }
00699 }
00700 
00701 void doPropertyTest( DWFContent* pContent )
00702 {
00703     bool bDone = false;
00704 
00705     wcout << L"Enter \'-\' by itself to quit" << endl;
00706     while (!bDone)
00707     {
00708         char cElementType = char(0);
00709         char cIdentifier = char(0);
00710 
00711         //
00712         //  Get element type to query
00713         //
00714         while (cElementType!='e' && cElementType!='o')
00715         {
00716             wcout << L"Element type to query - 'e'ntity or 'o'bject ('-' to quit): ";
00717             cin >> cElementType;
00718             if (cElementType=='-')
00719             {
00720                 return;
00721             }
00722         }
00723 
00724         //
00725         //  Get element identifier type
00726         //
00727         while (cIdentifier!='l' && cIdentifier!='i')
00728         {
00729             wcout << L"Get element by 'l'abel or by 'i'd ('-' to quit): ";
00730             cin >> cIdentifier;
00731             if (cIdentifier=='-')
00732             {
00733                 return;
00734             }
00735         }
00736 
00737         //
00738         //  Get element identifier value
00739         //
00740         wcout << L"Enter the " << (cIdentifier=='l'?L"label":L"id") << L": ";
00741         DWFString zIdentifier = getLine();
00742         if (zIdentifier==L"-")
00743         {
00744             return;
00745         }
00746         wcout << endl;
00747 
00748         //
00749         //  Get element using element type, and identifier type and value
00750         //
00751         DWFContentElement* pElem = NULL;
00752         if(cElementType=='e')
00753         {
00754             if (cIdentifier=='l')
00755             {
00756                 DWFEntity::tMap::Iterator* piEntity = pContent->getEntities();
00757                 if (piEntity)
00758                 {
00759                     for (; piEntity->valid(); piEntity->next())
00760                     {
00761                         if (piEntity->value()->getLabel()==zIdentifier)
00762                         {
00763                             pElem = piEntity->value();
00764                             break;
00765                         }
00766                     }
00767                 }
00768             }
00769             else
00770             {
00771                 pElem = pContent->getEntity( zIdentifier );
00772             }
00773         }
00774         else
00775         {
00776             if (cIdentifier=='l')
00777             {
00778                 DWFObject::tMap::Iterator* piObject = pContent->getObjects();
00779                 if (piObject)
00780                 {
00781                     for (; piObject->valid(); piObject->next())
00782                     {
00783                         if (piObject->value()->getLabel()==zIdentifier)
00784                         {
00785                             pElem = piObject->value();
00786                             break;
00787                         }
00788                     }
00789                 }
00790             }
00791             else
00792             {
00793                 pElem = pContent->getObject( zIdentifier );
00794             }
00795         }
00796 
00797         if (pElem==NULL)
00798         {
00799             wcout << L"The requested element was not found in the global content\n\n" << endl;
00800             continue;
00801         }
00802 
00803         bDone = performPropertyQueries( pElem );
00804     }
00805 }
00806 
00807 bool performPropertyQueries( DWFContentElement* pElem )
00808 {
00809     bool bQuitApp = false;
00810 
00811     DWFObject* pObject = dynamic_cast<DWFObject*>(pElem);
00812     if (pObject)
00813     {
00814         wcout << L"Object: " << pObject->id();
00815         if (pObject->getLabel().chars())
00816         {
00817             wcout << "; label: " << pObject->getLabel() << endl;
00818         }
00819         else
00820         {
00821             wcout << endl;
00822         }
00823         DWFEntity* pEntity = pObject->getEntity();
00824         wcout << L"Object's Entity: " << pEntity->id();
00825         if (pEntity->getLabel().chars())
00826         {
00827             wcout << "; label: " << pEntity->getLabel();
00828         }
00829         wcout << endl;
00830     }
00831     else
00832     {
00833         wcout << L"Entity: " << pElem->id() << endl;
00834         if (pElem->getLabel().chars())
00835         {
00836             wcout << "; label: " << pElem->getLabel();
00837         }
00838         wcout << endl;
00839     }
00840     wcout << endl;
00841 
00842     {
00843         wcout << L"Default Properties :-- " << endl;
00844         DWFProperty::tIterator* piProperty = pElem->getAllProperties();
00845         if (piProperty)
00846         {
00847             for (; piProperty->valid(); piProperty->next())
00848             {
00849                 DWFProperty* pProperty = piProperty->get();
00850                 wcout << L"Property: ( " << pProperty->name() << L" , " << pProperty->value();
00851                 if (pProperty->category().chars()>0)
00852                 {
00853                     wcout << L" , " << pProperty->category();
00854                 }
00855                 wcout << L" )" << endl;
00856             }
00857 
00858             DWFCORE_FREE_OBJECT( piProperty );
00859         }
00860     }
00861     wcout << endl;
00862 
00863     {
00864         bool bSkip = false;
00865 
00866         wcout << L"Single Property:-- " << endl;
00867         wcout << "Property Name ('-' to quit, '+' to skip): ";
00868         DWFString zProperty = getLine();
00869         if (zProperty == "-")
00870         {
00871             return true;
00872         }
00873         else if (zProperty == "+")
00874         {
00875             bSkip = true;
00876         }
00877 
00878         if (!bSkip)
00879         {
00880             wcout << "Category, this may be empty ('-' to quit): ";
00881             DWFString zCategory = getLine();
00882             if (zCategory=="-")
00883             {
00884                 return true;
00885             }
00886             const DWFProperty* pProperty = pElem->getProperty( zProperty, zCategory );
00887             if (pProperty)
00888             {
00889                 wcout << "Value: " << pProperty->value() << endl;
00890             }
00891             else
00892             {
00893                 wcout << "Property not found" << endl;
00894             }
00895         }
00896     }
00897     wcout << endl;
00898 
00899     {
00900         bool bSkip = false;
00901 
00902         wcout << L"BOM Properties (assuming a BOM which allows defaults):-- " << endl;
00903         char cIDType = char(0);
00904         while (cIDType!='t' && cIDType!='a')
00905         {
00906             wcout << L"Get by  Se't' or  Schem'a' ID ('-' to quit, '+' to skip): ";
00907             cin >> cIDType;
00908             if (cIDType == '-')
00909             {
00910                 return true;
00911             }
00912             else if (cIDType == '+')
00913             {
00914                 bSkip = true;
00915                 break;
00916             }
00917         }
00918 
00919         if (!bSkip)
00920         {
00921             wcout << (cIDType=='t'?"Set":"Schema") << " ID : ";
00922             DWFString zID = getLine();
00923             if (zID == "-")
00924             {
00925                 return true;
00926             }
00927 
00928             DWFProperty::tIterator* piProperty = NULL;
00929             if (cIDType == 't')
00930             {
00931                 piProperty = pElem->getAllPropertiesBySetID( zID );
00932             }
00933             else
00934             {
00935                 piProperty = pElem->getAllPropertiesBySchemaID( zID );
00936             }
00937 
00938             if (piProperty == NULL ||
00939                 piProperty->valid()==false)
00940             {
00941                 wcout << L"No properties were found with the given " <<  (cIDType=='t'?"Set":"Schema") << " ID" << endl;
00942             }
00943             else
00944             {
00945                 for (; piProperty->valid(); piProperty->next())
00946                 {
00947                     DWFProperty* pProperty = piProperty->get();
00948                     wcout << L"Property: ( " << pProperty->name() << L" , " << pProperty->value();
00949                     if (pProperty->category().chars()>0)
00950                     {
00951                         wcout << L" , " << pProperty->category();
00952                     }
00953                     wcout << L" )" << endl;
00954                 }
00955             }
00956 
00957             if (piProperty)
00958             {
00959                 DWFCORE_FREE_OBJECT( piProperty );
00960             }
00961         }
00962     }
00963     wcout << endl;
00964 
00965     wcout << endl;
00966  
00967     return bQuitApp;
00968 }
00969 
00970 
00971 

Generated on Tue Jan 6 22:40:01 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5