首页 > 其他分享 >Teamcenter_SOA开发:使用查询构建器查询数据

Teamcenter_SOA开发:使用查询构建器查询数据

时间:2023-03-31 21:05:04浏览次数:58  
标签:SOA string namespace argv 查询 Teamcenter using include

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

  1 //tcnx_projectexe.h
  2 #pragma once
  3 // Mandatory UF Includes
  4 #include <uf.h>
  5 #include <uf_object_types.h>
  6 #include <uf_ugmgr.h>
  7 #include <uf_part.h>
  8 #include <uf_disp.h>
  9 #include <uf_modl.h>
 10 #include <uf_obj.h>
 11 #include <uf_assem.h>
 12 
 13 // Internal+External Includes
 14 #include <NXOpen/Annotations.hxx>
 15 #include <NXOpen/Assemblies_Component.hxx>
 16 #include <NXOpen/Assemblies_ComponentAssembly.hxx>
 17 #include <NXOpen/Body.hxx>
 18 #include <NXOpen/BodyCollection.hxx>
 19 #include <NXOpen/Face.hxx>
 20 #include <NXOpen/Line.hxx>
 21 #include <NXOpen/NXException.hxx>
 22 #include <NXOpen/NXObject.hxx>
 23 #include <NXOpen/Part.hxx>
 24 #include <NXOpen/PartCollection.hxx>
 25 #include <NXOpen/Session.hxx>
 26 
 27 #include <NXOpen/PDM_PdmSession.hxx>
 28 #include <NXOpen/PDM_SoaConnectionHandle.hxx>
 29 #include <teamcenter/soa/client/Connection.hxx>
 30 #include <teamcenter/services/core/DatamanagementService.hxx>
 31 #include <teamcenter/soa/common/Version.hxx>
 32 
 33 // check mate
 34 #include <NXOpen/Validate_ValidationManager.hxx>
 35 #include <NXOpen/Validate_Validator.hxx>
 36 #include <NXOpen/Validate_ValidatorOptions.hxx>
 37 #include <NXOpen/Validate_Parser.hxx>
 38 
 39 // Std C++ Includes
 40 #include <iostream>
 41 #include <sstream>
 42 #include <stdio.h>
 43 #include <stdlib.h>
 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 <teamcenter/soa/client/model/User.hxx>
 80 #include <teamcenter/soa/client/RuntimeException.hxx>
 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 _UFUGMGR
103         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 #else
116         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<std::string> _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 #endif
159 
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 <teamcenter/schemas/soa/_2006_03/exceptions/ServiceException.hxx>
 25 #include <teamcenter/services/query/SavedqueryService.hxx>
 26 #include <teamcenter/services/core/DatamanagementService.hxx>
 27 #include <teamcenter/soa/client/model/ImanQuery.hxx>
 28 #include <teamcenter/soa/client/NotLoadedException.hxx>
 29 
 30 #include <iostream>
 31 #include <vector>
 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<Teamcenter::Services::Query::_2008_06::Savedquery::QueryInput> 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 time
103         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<string> 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<ModelObject* > 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动图:

 

 

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

 

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

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

标签:SOA,string,namespace,argv,查询,Teamcenter,using,include
From: https://www.cnblogs.com/huangym1/p/17272856.html

相关文章

  • Teamcenter_SOA开发:使用SOA登录Teamcenter
    本文TeamcenterSOA使用C++参考SOA的例子进行编写,以下代码为登录Teamcenter,代码工程在Teamcenter四层环境下运行。SOA的库文件、样例文件、帮助文件在Teamcenter的安装包中可以找到。  运行以下bat文件打开vs后再打开工程,不然调试运行会报错:1cd/d%~dp02setUGII_......
  • java查询hbase
    Mark——java查询hbase,https://blog.csdn.net/weixin_46408961/article/details/124224169查询Hbase数据分为Get方式查询,Scan方式查询,Scan配合Filter过滤查询01.Get方式查询importorg.apache.hadoop.conf.Configuration;importorg.apache.hadoop.hbase.Cell;importorg.ap......
  • MyBatis 框架的多表查询的实现
    1、表与表的联系类型一对一(1:1)一对多(1:n或n:1)多对多(n:m)2、Mybatis中实现多表查询的重要标签resultMap在Mybatis框架中,resultMap标签可以表示两个表之间的一对多和一对一关系。如:一个系可以有多个学生,如果想查询每个系的学生信息时,可以在Depar......
  • 洛谷P3374 【模板】树状数组 1-(单点修改,区间查询)
    题目描述如题,已知一个数列,你需要进行下面两种操作:将某一个数加上 x求出某区间每一个数的和输入格式第一行包含两个正整数 n,m,分别表示该数列数字的个数和操作的总个数。第二行包含 n 个用空格分隔的整数,其中第 i 个数字表示数列第 i 项的初始值。接下来 ......
  • 洛谷P3368 【模板】树状数组 2-(区间修改,单点查询)
    题目描述如题,已知一个数列,你需要进行下面两种操作:将某区间每一个数加上 x;求出某一个数的值。输入格式第一行包含两个整数 N、M,分别表示该数列数字的个数和操作的总个数。第二行包含 N 个用空格分隔的整数,其中第 i 个数字表示数列第 i 项的初始值。接下来......
  • 你还在手写 join 联表查询?MyBatis-Plus 这样写太香了!
    使用方法安装Maven<dependency><groupId>com.github.yulichang</groupId><artifactId>mybatis-plus-join</artifactId><version>1.2.4</version></dependency>Gradleimplementation'com.github.yulic......
  • 【python基础】python字典根据值查询键
    前言 测试>>>tfl_label={'circle_green':0,'circle_red':1,'circle_yellow':2,'left_green':3,'left_red':4,'left_yellow':5,'nomotor_green':6,'nomotor_red':7,......
  • 使用SpringBoot异步方法优化报销单查询接口,提高接口响应速度
    合理使用异步方法可以提高接口性能。异步方法适用于逻辑与逻辑之间可以相互分割互不影响的业务中。SpringBoot支持异步方法调用。具体用法:在启动类添加@EnableAsync注解,声明开启异步方法在异步方法添加@Async注解,被@Async注解修改的方法由SpringBoot默认线程池(SimpleAsyncTas......
  • Java 根据地址查询经纬度
    百度开放平台控制台:https://lbsyun.baidu.com/apiconsole/key#/home经纬度比较网址:https://jingweidu.bmcx.com/1、创建应用 2、写Java服务 /***通过字符串地址获取经纬度*@Author:menghaipeng*@Date:2023/3/3111:31*/publicclassDistanceUtil{......
  • mysql的查询--子查询,order by,group by,having
    一、1.多表查询 格式1: select字段列表 from表1join表2on表1.字段1=表2.字段1 where查询条件 格式2: select字段列表 from表1join表2on表1.字段1=表2.字段1 join表3on表2.字段2=表3.字段2 where查询条件 格式......