3D PLM Enterprise Architecture |
User Interface - Frame |
Creating Search QueriesHow to create queries to look for objects in V5 document ? |
Use Case |
AbstractThis article shows how to create and launch queries to look for objects in V5 documents. |
This use case is intended to show you how to create and launch queries to look for objects in V5 documents. You will specially learn:
Before getting to the use case itself, it is important to already be familiar with the basic notions of the Search. See the referenced article [1] for an overview.
[Top]
CAACafSearch is a use case of the CAACATIAApplicationFrm.edu framework that illustrates InteractiveInterfaces framework capabilities.
[Top]
The CAACafSearch use case is a state command [2] integrated in the frame V5 thanks to an add-in of the General workshop [3]. It means that the command is available whatever the open document.
This command, the Search Demonstrator... command, proposes to the end user the choice between pre-defined criteria and several contexts thanks to this user interface:
There are height pre-defined criteria which are the following:
All the criteria will be created and deleted at the beginning of the state command. Only the text of the criteria (in NLS or Transformat format) will be kept before its destruction. When the end user clicks the Launch button, an action method is triggered. In this method, a criterion is re-created from the text. A query with this criterion and with the current context is launched.
|
There are four contexts which are the following:
Refer to the technical article [1] for more details about these four contexts. |
When the end user clicks on the Launch button, the count of found elements is displayed in the editor and the elements are pre-highlighted.
This picture shows the result for the first query. Three elements are highlighted in the specification tree. In the visible space of the 3D viewer, only the point and the extrude are pre-highlighted. The sketch will appear in pre-highlighted mode if you switch to the hidden space. |
[Top]
To launch CAACafSearch , you will need to set up the build time environment, then compile CAACafSearch along with its prerequisites, set up the run time environment, and then execute the use case [4].
But just before launching the execution, edit the CAAApplicationFrame.edu.dico interface dictionary file located in the dictionary directory of the CAAApplicationFrame.edu framework:
Windows | InstallRootDirectory\CAAApplicationFrame.edu\CNext\code\dictionary\ |
UNIX | InstallRootDirectory/CAAApplicationFrame.edu/CNext/code/dictionary/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
In this file, remove the "#" character before the two following lines, and then run mkCreateRuntimeView.
... #CAAAfrGeneralWksAddin CATIWorkbenchAddin libCAAAfrGeneralWksAddin #CAAAfrGeneralWksAddin CATIAfrGeneralWksAddin libCAAAfrGeneralWksAddin ... |
The two line deal with the General workshop add-in described in the CAAAfrGeneralWksAddin use case [3] located in the CAAAfrGeneralWksAddin.m module (CAAApplicationFrame.edu framework)
Then, in the window where you run the mkrun command, do not type the module name on the command line, but type CNEXT instead. When the application is ready, do the following:
(*) The document is located in the InputData directory of the CAACATIAApplicationFrm.edu framework:
Windows | InstallRootDirectory\CAACATIAApplicationFrm.edu\InputData\ |
Unix | InstallRootDirectory/CAACATIAApplicationFrm.edu/InputData/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
The CAACafSearch use case is made of several classes located in the CAACafSearch.m module of the CAACATIAApplicationFrm.edu framework:
Windows | InstallRootDirectory\CAA CATIAApplicationFrm .edu\CAACafSearch.m\ |
Unix | InstallRootDirectory/CAA CATIAApplicationFrm .edu/CAACafSearch.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
There are three classes:
CAACafSearchCmd | The state command which creates the queries and enables the end user to launch them and see the result in the PSO. Only the piece of code in relationship with the Search API will be explained here. |
CAACafSearchDlg | The dialog box associated with the CAACafSearchCmd state command. This class will be not detailed here. |
CAACafLaunchNextQueryNotification | The notification sent by the CAACafSearchDlg command when the end user clicks the Launch button. This notification will be received by the CAACafSearchCmd command to valuate a dialog agent [5] and trigger an action to launch the query and display the result. This class will be not detailed here. |
The pre-requisite code is the add-in of the General workshop. This add-in contains the Search Demonstrator command. Refer to the Where to Find the CAAAfrGeneralWksAddin Code section of the CAAAfrGeneralWksAddin [3] use case for details.
[Top]
There are four logical steps in CAACafSearch:
[Top]
In the CAACafSearchCmd class constructor, the Search components always used during the state command are created. Each component (xxx) is instantiated by the CATCreateInstance global function and thanks a CLSID contained in the CATIniSearchxxxComponent file [6]
... #include "CATIIniSearchServices.h" #include "CATIIniSearchEngine.h" #include "CATIIniSearchContext.h" #include "CATIniSearchEngineComponent.h" #include "CATIniSearchContextComponent.h" #include "CATIniSearchServicesComponent.h" ... ::CATCreateInstance(CLSID_CATIniSearchEngineComponent, NULL, 0, IID_CATIIniSearchEngine, (void**)&_pIniSearchEngineOnCurrentEngine); ::CATCreateInstance(CLSID_CATIniSearchContextComponent, NULL, 0, IID_CATIIniSearchContext, (void**)&_pIniSearchContextOnCurrentContext); ::CATCreateInstance(CLSID_CATIniSearchServicesComponent, NULL, 0, IID_CATIIniSearchServices, (void**)&_pIniSearchServices); ... |
The first component is the Search engine component. It is handled by _pIniSearchEngineOnCurrentEngine
a CATIIniSearchEngine interface pointer. It will be used in an
action method of the CAACafSearchCmd to launch the query selected by the
end user.
The second component is the Search context component. It is handled by _pIniSearchContextOnCurrentContext
a CATIIniSearchContext interface pointer. Before launching the
query, the context selected by the end user will be retrieved from the CAACafSearchDlg
class instance. The context component is one parameter of the query, the second being
the criterion.
The third component is a component of services. It is handled by _pIniSearchServices
a CATIIniSearchServices interface pointer.
The service's component is used in the Creating Queries section for the Name Based Criterion, and like the first two components, in the Launching Queries section too.
[Top]
eight criteria (Fig. 3) are created in a method called by the CAACafSearchCmd constructor. For each criterion the methodology is the same:
The text is kept for two raisons: to build the contents of the CAACafSearchDlg's combo and to re-create the criterion just before launching the query.
Simple criteria:
Advanced criteria:
Goal: Retrieve all the objects with the red color (255,0,0).
First the color criterion component is created. pIniSearchColorCriterion
is a CATIIniSearchColorCriterion interface pointer and an handle
of the component.
... CATIIniSearchColorCriterion * pIniSearchColorCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchColorCriterionComponent, NULL, 0, IID_CATIIniSearchColorCriterion, (void**)&pIniSearchColorCriterion); ... |
Thanks, to the CATIIniSearchColorCriterion interface, the color parameters can be set:
... unsigned int *Color = new unsigned int[3]; Color[0]=255; Color[1]=0; Color[2]=0; CATUnicodeString ColorName; rc = pIniSearchColorCriterion->FindColorNameFromRGBColorCode(Color,ColorName); ... rc = pIniSearchColorCriterion->SetParameters(Color[0],Color[1],Color[2], CATIniSearchEnumeration::Equal, ColorName); delete []Color; ... |
The FindColorNameFromRGBColorCode
method retrieves from the
three color components the name of the color. If no name exists, the method
returns E_FAIL. There are 48 (basic colors) + 16 (custom colors) names
possible. This name, ColorName
, is set as argument of the SetParameters
method to be displayed in the criterion text.
Finally, the text of the criterion is retrieved.
... CATIIniSearchCriterion * pSearchCriterion = NULL ; rc = pIniSearchColorCriterion->QueryInterface(IID_CATIIniSearchCriterion, (void**) &pSearchCriterion); ... CATUnicodeString Text = "" ; pSearchCriterion->GetNLSQuery(Text); ... ... |
Color=Basic 25 |
The name "Basic 25" is the name of the red color.
Goal: Retrieve all the objects with the color (253,4,191) and which are visible.
First the color criterion component is created. pIniSearchColorCriterion
is a CATIIniSearchColorCriterion interface pointer and an handle of the component.
... CATIIniSearchColorCriterion * pIniSearchColorCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchColorCriterionComponent, NULL, 0, IID_CATIIniSearchColorCriterion, (void**)&pIniSearchColorCriterion); ... |
Then the three color components are set as argument of the color component but not the name of the color. See the text of the criterion.
... unsigned int *Color = new unsigned int[3]; Color[0]=253; Color[1]=4; Color[2]=191; rc = pIniSearchColorCriterion->SetParameters(Color[0],Color[1],Color[2], CATIniSearchEnumeration::Equal); delete []Color; ... |
Then, the visibility criterion component is created. pIniSearchVisibilityCriterion
is a CATIIniSearchVisibilityCriterion interface pointer and an handle of the component.
... CATIIniSearchVisibilityCriterion * pIniSearchVisibilityCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchVisibilityCriterionComponent, NULL, 0, IID_CATIIniSearchVisibilityCriterion, (void**)&pIniSearchVisibilityCriterion); ... |
The value of the criteria, CATShowAttr
, and the sign of
comparison, Equal
, are set with the SetParameters
method.
... rc = pIniSearchVisibilityCriterion->SetParameters( CATIIniSearchVisibilityCriterion::CATShowAttr, CATIniSearchEnumeration::Equal); ... |
The third criterion is a logical combination of the two criteria just above created. It is an And operation.
... CATIIniSearchAndCriterion * pIniSearchAndCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchAndCriterionComponent, NULL, 0, IID_CATIIniSearchAndCriterion, (void**)&pIniSearchAndCriterion); |
The color and the visibility criteria are set as argument of the combination criterion:
... rc = pIniSearchAndCriterion->SetParameters(pIniSearchVisibilityCriterion, pIniSearchColorCriterion); ... |
Finally, the text of the criterion is retrieved. It is a NLS text.
... CATIIniSearchCriterion * pSearchCriterion = NULL ; rc = pIniSearchAndCriterion->QueryInterface(IID_CATIIniSearchCriterion, (void**) &pSearchCriterion); ... CATUnicodeString Text = "" ; pSearchCriterion->GetNLSQuery(Text); ... ... |
(Visibility=Visible & Color='(253,141,91)') |
Note that the color is with the (r, g, b) format since the name of the color has not been set as parameter of the criterion.
Goal: Retrieve all the dotted lines whose the thickness is superior to .1mm.
First the dashed (line type) criterion component is created. pIniSearchDashedCriterion
is a CATIIniSearchDashedCriterion interface pointer and an handle of the component.
... CATIIniSearchDashedCriterion * pIniSearchDashedCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchDashedCriterionComponent, NULL, 0, IID_CATIIniSearchDashedCriterion, (void**)&pIniSearchDashedCriterion); ... |
Then the value of the line type and the sign of comparison are set as argument.
The value of the line type can be an index value, refer to the Get
/SetLineType
methods of the CATVisPropertiesValues class for the
possible values, or can be a string. In our sample, it is the
"Dotted" string. It is a NLS name. The "Dashed" combo in the Search
command displays all the NLS names.
... rc = pIniSearchDashedCriterion->SetParameters("Dotted", CATIniSearchEnumeration::Equal); ... |
Then, the weight criterion component is created. pIniSearchWeightCriterion
is a CATIIniSearchWeightCriterion interface pointer and an handle of the component.
... CATIIniSearchWeightCriterion * pIniSearchWeightCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchWeightCriterionComponent, NULL, 0, IID_CATIIniSearchWeightCriterion, (void**)&pIniSearchWeightCriterion); ... |
Then the value of the criteria and the sign of comparison are set.
... float weight = .1f ; rc = pIniSearchWeightCriterion->SetParameters(weight, CATIniSearchEnumeration::Superior); ... |
The third criterion is a logical combination of the two criteria just above created. It is an And operation.
... CATIIniSearchAndCriterion * pIniSearchAndCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchAndCriterionComponent, NULL, 0, IID_CATIIniSearchAndCriterion, (void**)&pIniSearchAndCriterion); ... |
The dashed and the weight criteria are set as argument of the combination criterion.
... rc = pIniSearchAndCriterion->SetParameters(pIniSearchWeightCriterion, pIniSearchDashedCriterion); ... |
Finally, the text of the criterion is retrieved. It is a NLS text.
... CATIIniSearchCriterion * pSearchCriterion = NULL ; rc = pIniSearchAndCriterion->QueryInterface(IID_CATIIniSearchCriterion, (void**) &pSearchCriterion); ... CATUnicodeString Text = "" ; pSearchCriterion->GetNLSQuery(Text); ... ... |
(Weight>0.1mm & Dashed=Dotted) |
Goal: Retrieve all the objects which are either on layer 2 or on the layer 3.
First a layer criterion component is created. pIniSearchLayer2Criterion
is a CATIIniSearchLayerCriterion interface pointer and an handle of the component.
... CATIIniSearchLayerCriterion * pIniSearchLayer2Criterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchLayerCriterionComponent, NULL, 0, IID_CATIIniSearchLayerCriterion, (void**)&pIniSearchLayer2Criterion); ... |
The index of the layer is set with the SetParameters
method.
... CATUnicodeString LayerIndex ; LayerIndex.BuildFromNum(2); rc = pIniSearchLayer2Criterion->SetParameters(LayerIndex, CATIniSearchEnumeration::Equal); ... |
Then a second layer criterion component is created. pIniSearchLayer3Criterion
is a CATIIniSearchLayerCriterion interface pointer and an handle of the component.
... CATIIniSearchLayerCriterion * pIniSearchLayer3Criterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchLayerCriterionComponent, NULL, 0, IID_CATIIniSearchLayerCriterion, (void**)&pIniSearchLayer3Criterion); ... |
The index of the layer is also set with the SetParameters
method.
... CATUnicodeString LayerIndex ; LayerIndex.BuildFromNum(3); rc = pIniSearchLayer3Criterion->SetParameters(LayerIndex, CATIniSearchEnumeration::Equal); ... |
The third criterion is a logical combination of the two criteria just above created. It is an Or operation.
... CATIIniSearchOrCriterion * pIniSearchOrCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchOrCriterionComponent, NULL, 0, IID_CATIIniSearchOrCriterion, (void**)&pIniSearchOrCriterion); ... |
The two layer criteria are set as argument of the combination criterion.
... rc = pIniSearchOrCriterion->SetParameters(pIniSearchLayer2Criterion, pIniSearchLayer3Criterion); ... |
Finally, the text of the criterion is retrieved. It is a NLS text.
... CATIIniSearchCriterion * pSearchCriterion = NULL ; rc = pIniSearchOrCriterion ->QueryInterface(IID_CATIIniSearchCriterion, (void**) &pSearchCriterion); ... CATUnicodeString Text = "" ; pSearchCriterion->GetNLSQuery(Text); ... ... |
(Layer=2 + Layer=3) |
Goal: Retrieve all the objects whose the name begins by the "Line" string but which does not contain the "Width" string. The first string is not case sensitive whereas the second one is case sensitive.
First a first name criterion component is created. pIniSearchNameLineCriterion
is a CATIIniSearchNameCriterion interface pointer and an handle of the component.
... CATIIniSearchNameCriterion * pIniSearchNameLineCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchNameCriterionComponent, NULL, 0, IID_CATIIniSearchNameCriterion, (void**)&pIniSearchNameLineCriterion); ... |
The name is "Line*", where * is not the wild card. The CorrectString
method enables you to create a string where the * character will be interpreted as
the star character and not as the wild card. The second argument of the CorrectString
method specifies that the input string do not contain a wild card. See the text
of the criterion.
... CATUnicodeString Name = "" ; CATUnicodeString StringToCorrect = "Line*" ; _pIniSearchServices->CorrectString(StringToCorrect,FALSE,Name); |
The string is associated with the name component thanks to the SetParameters
method. The string is not case sensitive, it means that the following strings
are valid: Line, line, LINE.
... CATBoolean CaseSensibility = FALSE ; rc = pIniSearchNameLineCriterion->SetParameters(Name,CaseSensibility, CATIniSearchEnumeration::Equal); ... |
Then, the second name criterion component is created. pIniSearchNameWidthCriterion
is a CATIIniSearchNameCriterion interface pointer and an handle of the component.
... CATIIniSearchNameCriterion * pIniSearchNameWidthCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchNameCriterionComponent, NULL, 0, IID_CATIIniSearchNameCriterion, (void**)&pIniSearchNameWidthCriterion); ... |
The string is associated with the name component thanks to the SetParameters
method. In this case, the star character is the wild card, no correction of
the string is
necessary. The string is case sensitive, it means that only the
"Width" string is valid.
... CATUnicodeString Name = "*Width*" ; CATBoolean CaseSensibility = TRUE ; rc = pIniSearchNameWidthCriterion->SetParameters(Name,CaseSensibility, CATIniSearchEnumeration::Equal); ... |
The third criterion is a logical combination of the two criteria just above created. It is an Except operation.
... CATIIniSearchExceptCriterion * pIniSearchExceptCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchExceptCriterionComponent, NULL, 0, IID_CATIIniSearchExceptCriterion, (void**)&pIniSearchExceptCriterion); ... |
The two name criteria are set as argument of the combination criterion. The order is important.
... rc = pIniSearchVisibilityCriterion->SetParameters(pIniSearchNameLineCriterion, pIniSearchNameWidthCriterion); ... |
Finally, the text of the criterion is retrieved. It is a Transformat text [1].
... CATIIniSearchCriterion * pSearchCriterion = NULL ; rc = pIniSearchAndCriterion->QueryInterface(IID_CATIIniSearchCriterion, (void**) &pSearchCriterion); ... CATUnicodeString Text = "" ; pSearchCriterion->GetTransFormatQuery(Text); ... ... |
(Name=Line'*' - Name_CAP=*Width*) |
The string Name
means that the string is not case sensitive
whereas Name_CAP
means that it is case sensitive.
An advanced criterion is composed of a knowledge type based criterion. This type, a CATIType, can be retrieved thanks to a dictionary [1].
... CATITypeDictionary_var pITypeDictionaryOnCurrentDic ; pITypeDictionaryOnCurrentDic = CATGlobalFunctions::GetTypeDictionary(); ... |
pITypeDictionaryOnCurrentDic
will be used in the further
sections.
Goal: Retrieve all the Hole features whose the diameter is superior or equal to 10mm.
First a type criterion component is created. pIniSearchTypeCriterion
is a CATIIniSearchTypeCriterion interface pointer and an handle of the component.
... CATIIniSearchTypeCriterion * pIniSearchTypeCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchTypeCriterionComponent, NULL, 0, IID_CATIIniSearchTypeCriterion, (void**)&pIniSearchTypeCriterion); ... |
The type associated with the Hole feature is retrieved thanks to the FindTypeInPackage
method. Refer to the Search technical article [1]
for details about the two first argument of this method. In this case, Hole
is a type of the PartDesign
package.
... CATIType_var TypePtr; rc = pITypeDictionaryOnCurrentDic->FindTypeInPackage("Hole","PartDesign",TypePtr); ... |
Then the type (a CATIType interface pointer) can be set as
argument of the type component. The last argument of the SetParameters
method is the internal name of the workbench which contains this type. The
list of workbenches appears in the "Workbench" combo of the Search
command. Refer to the technical article to know how to retrieve their
internal name [1].
... rc = pIniSearchTypeCriterion->SetParameters(TypePtr, CATIniSearchEnumeration::Equal,"CATPrtSearch"); ... |
The Diameter attribute is an attribute of type dimension. So, a dimension criterion component is created. pIniSearchDimensionCriterion
is a CATIIniSearchDimensionCriterion interface pointer and an handle of the component.
... CATIIniSearchDimensionCriterion * pIniSearchDimensionCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchDimensionCriterionComponent, NULL, 0, IID_CATIIniSearchDimensionCriterion, (void**)&pIniSearchDimensionCriterion); ... |
The dimension component is valuated with the internal name of the attribute [1], with the value of comparison and the sign of comparison.
... CATUnicodeString AttributeInternalName = "Diameter" ; CATUnicodeString AttributeValue = "10.0mm" ; CATUnicodeString AttributeNLSName = "Diameter" ; rc = pIniSearchDimensionCriterion->SetParameters(AttributeInternalName, AttributeValue, CATIniSearchEnumeration::SupEqual, AttributeNLSName); ... |
The third criterion is a logical combination between the type and the attribute criterion just above created. It is necessary an And operation.
... CATIIniSearchAndCriterion * pIniSearchAndCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchAndCriterionComponent, NULL, 0, IID_CATIIniSearchAndCriterion, (void**)&pIniSearchAndCriterion); ... |
The two name criteria are set as argument of the combination criterion. The order is important, the type criterion must be the first.
... rc = pIniSearchAndCriterion->SetParameters(pIniSearchTypeCriterion, pIniSearchDimensionCriterion); ... |
Finally, the text of the criterion is retrieved. It is a Transformat text [1].
... CATIIniSearchCriterion * pSearchCriterion = NULL ; rc = pIniSearchAndCriterion->QueryInterface(IID_CATIIniSearchCriterion, (void**) &pSearchCriterion); ... CATUnicodeString Text = "" ; pSearchCriterion->GetTransFormatQuery(Text); ... ... |
CATPrtSearch.Hole.Diameter>=10mm |
In a transformat string, all the name are internal names. CATPrtSearch
is the internal name of the workbench which contains the type. Hole
is the name of the type, and Diameter
is the name of the
attribute.
Goal: Retrieve all the Product features whose the Part Number name begins by the "CAAPart" string.
First a type criterion component is created. pIniSearchTypeCriterion
is a CATIIniSearchTypeCriterion interface pointer and an handle of the component.
... CATIIniSearchTypeCriterion * pIniSearchTypeCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchTypeCriterionComponent, NULL, 0, IID_CATIIniSearchTypeCriterion, (void**)&pIniSearchTypeCriterion); ... |
The type associated with the Product feature is retrieved thanks to the FindTypeInPackage
[1] method.
... CATIType_var TypePtr; rc = pITypeDictionaryOnCurrentDic->FindTypeInPackage("Product","ProductPackage", TypePtr); ... |
Then the type ( a CATIType interface pointer ) can be set as
argument of the type component. The last argument of the SetParameters
method is the internal name [1] of the workbench which
contains this type.
... rc = pIniSearchTypeCriterion->SetParameters(TypePtr, CATIniSearchEnumeration::Equal, "CATProductSearch"); ... |
The "Part Number" attribute is an attribute of type string. So, a
string criterion component is created. pIniSearchStringCriterion
is a CATIIniSearchStringCriterion interface pointer and an handle of the component.
... CATIIniSearchStringCriterion * pIniSearchStringCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchStringCriterionComponent, NULL, 0, IID_CATIIniSearchStringCriterion, (void**)&pIniSearchStringCriterion ); ... |
The string component is valuated with the internal name of
the attribute [1] with the value of comparison and the sign of comparison.
The last
argument of the method is the NLS Name of the attribute. This parameter is
optional, but if you don't set it, and no document which contains this
attribute has been loaded, the GetNlSQuery
method will return
E_FAIL.
... CATUnicodeString AttributeInternalName = "PartNumber" ; CATUnicodeString AttributeNLSName = "Part Number" ; CATUnicodeString AttributeValue = "CAAPart*" ; CATBoolean CaseSensibility = FALSE ; rc = pIniSearchStringCriterion->SetParameters(AttributeInternalName, AttributeValue, CaseSensibility , CATIniSearchEnumeration::Equal, AttributeNLSName); ... |
The third criterion is a logical combination between the type and the attribute criterion just above created. It is necessary an And operation.
... CATIIniSearchAndCriterion * pIniSearchAndCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchAndCriterionComponent, NULL, 0, IID_CATIIniSearchAndCriterion, (void**)&pIniSearchAndCriterion); ... |
The two name criteria are set as argument of the combination criterion. The order is important, the type criterion must be the first.
... rc = pIniSearchAndCriterion->SetParameters(pIniSearchTypeCriterion, pIniSearchStringCriterion); ... |
Finally, the text of the criterion is retrieved. It is a TransFormat text [1].
... CATIIniSearchCriterion * pSearchCriterion = NULL ; rc = pIniSearchAndCriterion->QueryInterface(IID_CATIIniSearchCriterion, (void**) &pSearchCriterion); ... CATUnicodeString Text = "" ; pSearchCriterion->GetTransformatQuery(Text); ... ... |
CATProductSearch.Product.PartNumber="CAAPart*" |
In a transformat string, all the name are internal names. CATProductSearch
is the internal name of the workbench which contains the type. Product
is the name of the type, and PartNumber
is the name of the
attribute. Compare with the next criterion text.
Goal: Retrieve all the Product features whose the value of the CAAAttr user attribute is inferior or equal to .1
First a type criterion component is created. pIniSearchTypeCriterion
is a CATIIniSearchTypeCriterion interface pointer and an handle of the component. See the previous section for the details.
The "CAAAttr" attribute is an user attribute. So, an User criterion component is created.
pIniSearchUserCriterion
is a CATIIniSearchUserCriterion interface pointer and an handle of the component.
... CATIIniSearchUserCriterion * pIniSearchUserCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchUserCriterionComponent, NULL, 0, IID_CATIIniSearchUserCriterion, (void**)&pIniSearchUserCriterion); ... |
The user component is valuated with the internal name of the attribute [1], with the value of comparison and the sign of comparison.
... CATUnicodeString AttributeInternalName = "CAAAttr" ; CATUnicodeString AttributeValue = ".1" ; rc = pIniSearchUserCriterion->SetParameters(AttributeInternalName, AttributeValue, CATIniSearchEnumeration::InfEqual); ... |
The third criterion is a logical combination between the type and the attribute criterion just above created. It is necessary an And operation.
... CATIIniSearchAndCriterion * pIniSearchAndCriterion = NULL ; rc = ::CATCreateInstance(CLSID_CATIniSearchAndCriterionComponent, NULL, 0, IID_CATIIniSearchAndCriterion, (void**)&pIniSearchAndCriterion); ... |
The two name criteria are set as argument of the combination criterion. The order is important, the type criterion must be the first.
... rc = pIniSearchAndCriterion->SetParameters(pIniSearchTypeCriterion, pIniSearchStringCriterion); ... |
Finally, the text of the criterion is retrieved. It is a NLS text [1].
... CATIIniSearchCriterion * pSearchCriterion = NULL ; rc = pIniSearchAndCriterion->QueryInterface(IID_CATIIniSearchCriterion, (void**) &pSearchCriterion); ... CATUnicodeString Text = "" ; pSearchCriterion->GetNLSQuery(Text); ... ... |
'Product Structure'.Product.CAAAttr<=.1 |
It is a NLS string, so all the names are translated. 'Product
Structure'
is the name of the workbench, Product
is the
name of the type and 'CAAAttr'
is the name of the attribute.
Compare with the previous criterion text.
[Top]
The end user has pushed the Launch button - See Fig 2 - an action method of the CAACafSearchCmd class is trigerred. This action method should first re-create the criterion from a text, retrieve the current context and then launch a query.
First the text of the criterion is retrieved from the end user selection.
... int CriterionIndex = -1 ; _pSearchDlg->GetCurrentCriterion(CriterionIndex); CATUnicodeString CriterionText = ""; if ( NULL != _pListCriterionTexts ) { if ( (CriterionIndex >= 1) && (CriterionIndex <= _pListCriterionTexts->Size()) ) { CriterionText = (*_pListCriterionTexts)[CriterionIndex]; } } ... |
Then, the context is retrieved with the GetCurrentContext
method, a CAACafSearchDlg class method.
... CATIIniSearchContext::Scope ContextValue = CATIIniSearchContext::Everywhere ; _pSearchDlg->GetCurrentContext(ContextValue); ... |
A criterion is re-created thanks to the DecodeStringToCriterion
method of the CATIIniSearchServices interface. _pIniSearchServices
is an handle on the service's component created in the Creating the Engine, Context and Services Components
section. CriterionText
is the text of the criterion, just above
retrieved, and pIniSearchCriterion
is the CATIIniSeachCriterion
interface pointer on the newly criterion. The second argument, FALSE
,
means that in case of error, no window will be launched.
... CATIIniSearchCriterion * pIniSearchCriterion = NULL ; rc = _pIniSearchServices->DecodeStringToCriterion(CriterionText, FALSE, pIniSearchCriterion); ... |
After the criterion creation, the context component can be
updated with the current scope. _pIniSearchContextOnCurrentContext
is an handle
on the context component created in the Creating the Engine, Context and Services Components
section.
... rc = _pIniSearchContextOnCurrentContext->SetScope(ContextValue); ... |
Then, the query is composed by using the context and the
criterion. _pIniSearchEngineOnCurrentEngine
is an handle on the search engine
component created in the Creating the Engine, Context and Services Components
section.
... rc = _pIniSearchEngineOnCurrentEngine->SetCriterionAndContext(pIniSearchCriterion, _pIniSearchContextOnCurrentContext); ... |
Finally, the query can be launched. The default argument of the LaunchSearchOnDocument
method, NULL,
is used. It means that the search is done on the
current document.
... rc = _pIniSearchEngineOnCurrentEngine->LaunchSearchOnDocument() ... |
The result of the search is analyzed in the next section.
[Top]
The found objects should be pre-highlighted. They will be set in
the CATPSO instance associated with the current document (in fact the
editor of the current document). This instance, _pPso
, has been
retrieved in the CAACafSearchCmd class constructor such as:
... CATFrmEditor * pEditor = GetEditor(); if ( NULL != pEditor ) { _pPso = pEditor->GetPSO(); } ... |
The GetEditor
method is a CATStateCommand
method. It retrieves the CATFrmEditor class instance associated with the
active document. This instance has created the CATPSO class instance [6].
The GetFoundObjects
method of the CATIIniSeachEngine
interface retrieves all the found objects. The returned value, pListOfFoundObjects,
is a CATSO object, it means that the method returns a list of complete
paths. Each value of the list is a CATPathElement (Visualization framework).
Note that pListOfFoundObjects
cannot be NULL, because
the GetFoundObjects
method returns E_FAIL
if no object
are found.
... CATSO * pListOfFoundObjects = NULL ; int nbelt = 0 ; _pIniSearchEngineOnCurrentEngine->GetFoundObjects(pListOfFoundObjects); ... |
Since several objects can be found, the complete path of the
objects are set in the CATPSO thanks to the AddElements
method, and after the last addition, the EndAddElements
is called.
... nbelt = pListOfFoundObjects->GetSize(); if ( NULL != _pPso ) { for ( int i= 0 ; i < nbelt ; i++ ) { CATBaseUnknown * pCurrent = (*pListOfFoundObjects)[i] ; if ( NULL != pCurrent ) { _pPso->AddElements(pCurrent); } } _pPso->EndAddElements(); } ... |
[Top]
This use case explains how to use the Search API to create queries and launch them.
[Top]
Version: 1 [May 2003] | Document created |
[Top] |
Copyright © 2003, Dassault Systèmes. All rights reserved.