最新要闻

广告

手机

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

家电

世界消息!Teamcenter_SOA开发:使用查询构建器查询数据

来源:博客园


(资料图片仅供参考)

Teamcenter中的查询构建器可以查询对象信息,今天使用Item Name这个查询来查询Teamcenter中的对象,并打印出对象的信息。搭建环境参见Teamcenter_SOA开发:使用SOA登录Teamcenter - huangym1 - 博客园 (cnblogs.com)

1 //tcnx_projectexe.h  2 #pragma once  3 // Mandatory UF Includes  4 #include   5 #include   6 #include   7 #include   8 #include   9 #include  10 #include  11 #include  12  13 // Internal+External Includes 14 #include  15 #include  16 #include  17 #include  18 #include  19 #include  20 #include  21 #include  22 #include  23 #include  24 #include  25 #include  26  27 #include  28 #include  29 #include  30 #include  31 #include  32  33 // check mate 34 #include  35 #include  36 #include  37 #include  38  39 // Std C++ Includes 40 #include  41 #include  42 #include  43 #include  44  45 using namespace NXOpen; 46 using namespace Teamcenter::Soa::Client; 47 using namespace Teamcenter::Services::Core; 48 using std::string; 49 using std::exception; 50 using std::stringstream; 51 using std::endl; 52 using std::cout; 53 using std::cerr; 54  55 #define MAX_UGMGR_NAME_LEN 1024 56 #define CREATION_DATE       1 57 #define MODIFICATION_DATE   2 58 static int indent_level = 0; 59  60 #define CHECK( func_ ) \ 61     ifail = (func_); \ 62 if (ifail != 0) {\ 63 printf("ERROR: %s returned %d", # func_, ifail); \ 64 return ifail;} 65  66 #define PRINT( content_ ) \ 67 { int ii; \ 68 for (ii = 0; ii < indent_level; ii++) \ 69 { printf("  "); } \ 70     printf content_; \ 71     printf("\n"); } 72  73  74 //tcnx_projectexe.cpp 75 #include "tcnx_projectexe.h" 76 #include "teamcenter/clientx/AppXSession.hxx" 77 #include "teamcenter/hello/HomeFolder.hxx" 78 #include "teamcenter/hello/Query.hxx" 79 #include  80 #include  81  82 using namespace Teamcenter::ClientX; 83 using namespace Teamcenter::Services::Core; 84 using namespace Teamcenter::Soa::Common; 85 using namespace Teamcenter::Soa::Client; 86 using namespace Teamcenter::Soa::Client::Model; 87 using namespace Teamcenter::Schemas::Soa::_2006_03::Exceptions; 88 using namespace Teamcenter::Hello; 89  90  91 //=================== 92 // Entry Point 93 //=================== 94 #ifdef WIN32 95 int _tmain(int argc, _TCHAR* argv[]) 96 #else 97 int main(int argc, char* argv[]) 98 #endif 99 {100     try{101 102 #ifdef _UFUGMGR103         int _errCode = 0;104         const char** consolePara = (const char**)(argv);105         logical is_active;106         _errCode = UF_is_ugmanager_active(&is_active);// 判断ugmanager环境是否已经初始化107         if (!is_active)108             _errCode = UF_UGMGR_initialize(argc, consolePara);// 初始化ugmanager环境109 110         //do_it();111         //_errCode = invokePdmServer();112 113         _errCode = UF_UGMGR_terminate();114         return _errCode;115 #else116         if (argc > 1){117             if (strcmp(argv[1], "-help") == 0 || strcmp(argv[1], "-h") == 0){118                 cout << "usage: Hello [-host http://server:port/tc] " << endl;119                 return 0;120             }121         }122 123         std::string serverHost = "http://plmdev:7001/tc";124         if (argc > 2 && strcmp(argv[1], "-host") == 0)125             serverHost = argv[2];126 127         string _username, _password;128         std::vector _tempStr;129         for (int idx = 0; idx < argc; idx++){130             _tempStr.push_back(argv[idx]);131             if (string(argv[idx]).find("-u=") != std::string::npos){132                 _username = string(argv[idx]).substr(string(argv[idx]).find_first_of("=") + 1);133             }134             else if (string(argv[idx]).find("-p=") != std::string::npos){135                 _password = string(argv[idx]).substr(string(argv[idx]).find_first_of("=") + 1);136             }137         }138 139         AppXSession     session(serverHost, _username, _password);140         HomeFolder  home;141         Query       query;142 143         try{144             User* user = session.login();145             if (!user)146                 return 0;147 148             home.listHomeFolder(user);149             query.queryItems();150 151             session.logout();152         }153         catch (Teamcenter::Soa::Client::RuntimeException& e){154             cout << e.getMessage() << endl;155             cout << "The application will terminate." << endl;156         }157         return 0;158 #endif159 160     }161     catch (const NXException& e1){162         cerr << "NXException: " << e1.ErrorCode() << endl;163         cerr << e1.Message() << endl;164     }165     catch (const exception& e2){166         cerr << "Exception: " << e2.what() << endl;167     }168     catch (...){169         cerr << "Unknown Exception: " << endl;170     }171 }
1 //Query.hpp  2 #ifndef TEAMCENTER_HELLO_QUERY_HXX  3 #define TEAMCENTER_HELLO_QUERY_HXX  4   5 namespace Teamcenter  6 {  7     namespace Hello  8     {  9         class Query; 10         class  Query 11         { 12         public: 13  14             void queryItems(); 15         }; 16     } 17 } //end namespace 18 #endif 19  20 //Query.cpp 21 #include "Query.hxx" 22 #include "../clientx/AppXSession.hxx" 23  24 #include  25 #include  26 #include  27 #include  28 #include  29  30 #include  31 #include  32  33 using namespace std; 34 using namespace Teamcenter::ClientX; 35 using namespace Teamcenter::Hello; 36 using namespace Teamcenter::Schemas::Soa::_2006_03::Exceptions; 37 using namespace Teamcenter::Services::Query; 38 using namespace Teamcenter::Services::Core; 39 using namespace Teamcenter::Soa::Common; 40 using namespace Teamcenter::Soa::Client; 41 using namespace Teamcenter::Soa::Client::Model; 42  43  44 void Query::queryItems() 45 { 46     ImanQuery *query; 47     SavedqueryService* queryService = SavedqueryService::getService(AppXSession::getConnection()); 48     DatamanagementService* dmService = DatamanagementService::getService(AppXSession::getConnection()); 49  50     try 51     { 52         SavedqueryService::GetSavedQueriesResponse savedQueries = queryService->getSavedQueries(); 53  54         if (savedQueries.queries.size() == 0){ 55             cout << "There are no saved queries in the system." << endl; 56             return; 57         } 58         for (size_t i = 0; i < savedQueries.queries.size(); i++) 59         { 60             if (savedQueries.queries[i].name == "Item Name") 61             { 62                 query = savedQueries.queries[i].query; 63                 break; 64             } 65         } 66     } 67     catch (ServiceException& e) 68     { 69         cout << "GetSavedQueries service request failed." << endl; 70         cout << e.getMessage() << endl; 71         return; 72     } 73     if (query == nullptr){ 74         cout << "There is not an "Item Name" query." << endl; 75         return; 76     } 77  78     try 79     { 80         // Search for all Items, returning a maximum of 25 objects 81         vector savedQueryInputs; 82         vector< ModelObject* > limitList; 83         vector< string > entries; 84         vector< string > values; 85         entries.push_back("Item Name"); 86         values.push_back("*"); 87         Teamcenter::Services::Query::_2008_06::Savedquery::QueryInput savedQueryInput; 88         savedQueryInput.query = query; 89         savedQueryInput.maxNumToReturn = 300; 90         savedQueryInput.limitList = limitList; 91         savedQueryInput.entries = entries; 92         savedQueryInput.values = values; 93         savedQueryInput.resultsType = 0; 94         savedQueryInputs.push_back(savedQueryInput); 95  96         SavedqueryService::SavedQueriesResponse queryResponse = queryService->executeSavedQueries(savedQueryInputs); 97         SavedqueryService::QueryResults found = queryResponse.arrayOfResults[0]; 98  99         cout << "" << endl;100         cout << "Found Items:" << endl;101 102         // Page through the results 10 at a time103         for (size_t i = 0; i < found.objectUIDS.size(); i += 10)104         {105             size_t pageSize = (i + 10 < found.objectUIDS.size()) ? 10 : found.objectUIDS.size() - i;106 107             vector uids;108             for (size_t j = 0; j < pageSize; j++){109                 uids.push_back(found.objectUIDS[i + j]);110             }111             ServiceData sd = dmService->loadObjects(uids);112             vector foundObjs = sd.getPlainObjs();113             AppXSession::printObjects(foundObjs);114         }115     }116     catch (ServiceException& e){117         cout << "ExecuteSavedQuery service request failed." << endl;118         cout << e.getMessage() << endl;119         return;120     }121 }

程序调试运行查询GIF动图:

黄河远上白云间,一片孤城万仞山。羌笛何须怨杨柳,春风不度玉门关。

诗人初到凉州,面对黄河、边城的辽阔景象,又耳听着《折杨柳》曲,有感而发,写成了这首表现戍守边疆的士兵思念家乡情怀的诗作。

诗的前两句描绘了西北边地广漠壮阔的风光。首句抓住自下(游)向上(游)、由近及远眺望黄河的特殊感受,描绘出“黄河远上白云间”的动人画面:汹涌澎湃波浪滔滔的黄河竟像一条丝带迤逦飞上云端。写得真是神思飞跃,气象开阔。诗人的另一名句“黄河入海流”,其观察角度与此正好相反,是自上而下的目送;而李白的“黄河之水天上来”,虽也写观望上游,但视线运动却又由远及近,与此句不同。“黄河入海流”和“黄河之水天上来”,同是着意渲染黄河一泻千里的气派,表现的是动态美。而“黄河远上白云间”,方向与河的流向相反,意在突出其源远流长的闲远仪态,表现的是一种静态美。同时展示了边地广漠壮阔的风光,不愧为千古奇句。

关键词: