Sample Code: Selection using SelectionOptionsKit.SetConditions

Version

HPS 2020

Language

C++

Description:

Sample code is an example on selection with Condition using SelectionOptionsKit.SetConditions

HPS::SegmentKey ModelSegKey = GetDocument()->GetModel().GetSegmentKey(); // Create Conditional Named Style HPS::PortfolioKey myPortfolio = HPS::Database::CreatePortfolio(); HPS::NamedStyleDefinition geometry_OFF = myPortfolio.DefineNamedStyle("vis_off", HPS::Database::CreateRootSegment()); geometry_OFF.GetSource().GetVisibilityControl().SetGeometry(false); ModelSegKey.GetPortfolioControl().Push(myPortfolio); ModelSegKey.GetStyleControl().PushNamed("vis_off"); ModelSegKey.GetVisibilityControl().SetFaces(true); // Create two subsegment and set a condition on SubSegment1 HPS::SegmentKey SubSegment1 = ModelSegKey.Subsegment(); HPS::SegmentKey SubSegment2 = ModelSegKey.Subsegment(); // setup conditional style on SubSegment1 SubSegment1.GetStyleControl().SetNamed("vis_off", "c1"); Point points[8] = { Point(0, 0, 0), Point(3, 0, 0), Point(3, 3, 0), Point(0, 3, 0) }; int faces[10] = { 4, 0, 1, 2, 3 }; HPS::ShellKey sk1 = SubSegment1.InsertShell(4, points, 5, faces); HPS::ShellKey sk2 = SubSegment2.InsertShell(4, points, 5, faces); SubSegment2.GetModellingMatrixControl().Translate(6, 0, 0); GetCanvas().GetAttachedLayout().GetAttachedView().FitWorld(); GetCanvas().UpdateWithNotifier().Wait(); auto myWindowKey = _canvas.GetWindowKey(); HPS::SelectionOptionsKit selectionOptions; selectionOptions.SetAlgorithm(HPS::Selection::Algorithm::Analytic); selectionOptions.SetLevel(HPS::Selection::Level::Entity); selectionOptions.SetScope(myWindowKey); selectionOptions.SetCondition("c1"); HPS::Rectangle selectionPoint(-1,1,-1,1); HPS::SelectionResults selectionResults; size_t numSelectedItems = myWindowKey.GetSelectionControl().SelectByArea( selectionPoint, selectionOptions, selectionResults); // EXPECTED: numSelectedItems == 1 because "selectionOptions.SetCondition("c1");" is called if (numSelectedItems == 1) { HPS::SelectionResultsIterator iter = selectionResults.GetIterator(); while (iter.IsValid()) { HPS::SelectionItem selectionItem = iter.GetItem(); Key key; selectionItem.ShowSelectedItem(key); // 'key' is the HPS::Key of the selected item if (key.Type() == HPS::Type::ShellKey) { printf("Selected Shell\n"); } iter.Next(); } }