1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_WidgetPoint2D.h"
10 #include "PartSet_Tools.h"
12 #include <XGUI_ModuleConnector.h>
13 #include <XGUI_Displayer.h>
14 #include <XGUI_Workshop.h>
15 #include <XGUI_Selection.h>
16 #include <XGUI_SelectionMgr.h>
18 #include <ModuleBase_IViewer.h>
19 #include <ModuleBase_IWorkshop.h>
20 #include <ModuleBase_IViewWindow.h>
21 #include <ModuleBase_Operation.h>
22 #include <ModuleBase_ISelection.h>
23 #include <ModuleBase_IPropertyPanel.h>
24 #include <ModuleBase_Operation.h>
26 #include <GeomDataAPI_Point2D.h>
28 #include <Events_Loop.h>
30 #include <SketchPlugin_Line.h>
31 #include <SketchPlugin_Sketch.h>
32 #include <SketchPlugin_Point.h>
33 #include <SketchPlugin_Arc.h>
34 #include <SketchPlugin_Circle.h>
35 #include <SketchPlugin_ConstraintLength.h>
36 #include <SketchPlugin_ConstraintDistance.h>
37 #include <SketchPlugin_ConstraintParallel.h>
38 #include <SketchPlugin_ConstraintPerpendicular.h>
39 #include <SketchPlugin_ConstraintRadius.h>
40 #include <SketchPlugin_ConstraintRigid.h>
42 #include <SelectMgr_IndexedMapOfOwner.hxx>
43 #include <StdSelect_BRepOwner.hxx>
45 #include <ModelAPI_Events.h>
47 #include <QMouseEvent>
48 #include <QApplication>
51 /// Returns list of unique objects by sum of objects from List1 and List2
52 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
53 const QList<ModuleBase_ViewerPrs>& theList2)
55 QList<ModuleBase_ViewerPrs> aRes;
56 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
57 if (!aRes.contains(aPrs))
60 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
61 if (!aRes.contains(aPrs))
67 void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
68 QMap<FeaturePtr, QList<AttributePtr> >& theFeature2AttributeMap,
69 const FeaturePtr theSketch)
71 QList<ModuleBase_ViewerPrs> aRes;
73 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
74 aLast = theList.end();
75 for (; anIt != aLast; anIt++)
77 ModuleBase_ViewerPrs aPrs = *anIt;
78 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
79 if (aFeature.get() == NULL)
82 QList<AttributePtr> anAttributes;
83 if (theFeature2AttributeMap.contains(aFeature)) {
84 anAttributes = theFeature2AttributeMap[aFeature];
87 TopoDS_Shape aShape = aPrs.shape();
88 if (!aShape.IsNull()) {
89 if (aShape.ShapeType() == TopAbs_VERTEX) {
90 anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
91 if (anAttr.get() != NULL && !anAttributes.contains(anAttr))
92 anAttributes.push_back(anAttr);
95 theFeature2AttributeMap[aFeature] = anAttributes;
102 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
103 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false)
105 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
106 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
108 myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
110 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
111 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
113 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
114 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
116 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
117 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
119 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
120 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
123 PartSet_SketcherMgr::~PartSet_SketcherMgr()
125 if (!myPlaneFilter.IsNull())
126 myPlaneFilter.Nullify();
129 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
132 if (!(theEvent->buttons() & Qt::LeftButton))
135 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
136 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
137 // Use only for sketch operations
138 if (aOperation && myCurrentSketch) {
139 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
142 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
143 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
145 // Avoid non-sketch operations
146 if ((!isSketchOpe) && (!isSketcher))
149 bool isEditing = aOperation->isEditOperation();
151 // Ignore creation sketch operation
152 if ((!isSketcher) && (!isEditing))
155 // MoveTo in order to highlight current object
156 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
157 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
159 // Remember highlighted objects for editing
160 ModuleBase_ISelection* aSelect = aWorkshop->selection();
161 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
162 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
163 myFeature2AttributeMap.clear();
165 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
167 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
168 fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
171 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
174 if (myFeature2AttributeMap.empty()) {
175 if (isSketchOpe && (!isSketcher))
176 // commit previous operation
177 if (!aOperation->commit())
185 get2dPoint(theWnd, theEvent, myCurX, myCurY);
187 aWorkshop->viewer()->enableMultiselection(false);
190 } else if (isSketchOpe && isEditing) {
191 // If selected another object commit current result
192 aOperation->commit();
195 get2dPoint(theWnd, theEvent, myCurX, myCurY);
197 aWorkshop->viewer()->enableMultiselection(false);
199 // This is necessary in order to finalize previous operation
200 QApplication::processEvents();
206 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
208 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
209 ModuleBase_Operation* aOp = aWorkshop->currentOperation();
212 if (!sketchOperationIdList().contains(aOp->id()))
215 // Only for sketcher operations
216 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
218 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
219 myIsDragging = false;
221 aViewer->enableMultiselection(true);
223 myFeature2AttributeMap.clear();
225 // Reselect edited object
226 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
227 if (theEvent->modifiers() & Qt::ShiftModifier)
228 aViewer->AISContext()->ShiftSelect();
230 aViewer->AISContext()->Select();
235 if (!aViewer->isMultiSelectionEnabled()) {
236 aViewer->enableMultiselection(true);
240 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
243 // the selection should be switched off in order to do not deselect moved objects by the
245 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
246 aViewer->enableSelection(false);
248 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
249 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
250 return; // No edit operation activated
252 Handle(V3d_View) aView = theWnd->v3dView();
253 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
255 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
256 double dX = aX - myCurX;
257 double dY = aY - myCurY;
259 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
260 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
261 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
262 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
264 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
265 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
267 FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
268 aLast = myFeature2AttributeMap.end();
269 FeatureToSelectionMap aCurrentSelection;
270 for (; anIt != aLast; anIt++) {
271 FeaturePtr aFeature = anIt.key();
274 AttributeList anAttributes = anIt.value();
275 if (!anAttributes.empty()) {
276 anAttr = anAttributes.first();
279 // save the previous selection
280 getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, aCurrentSelection);
281 // save the previous selection: end
283 // Process selection by attribute: the priority to the attribute
284 if (anAttr.get() != NULL) {
285 std::string aAttrId = anAttr->id();
286 DataPtr aData = aFeature->data();
287 if (aData.get() != NULL) {
288 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
289 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
290 if (aPoint.get() != NULL) {
291 bool isImmutable = aPoint->setImmutable(true);
292 aPoint->move(dX, dY);
293 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
294 aPoint->setImmutable(isImmutable);
298 // Process selection by feature
299 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
300 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
301 if (aSketchFeature) {
302 aSketchFeature->move(dX, dY);
303 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
307 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
308 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
310 // restore the previous selection
311 FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
312 aSLast = aCurrentSelection.end();
313 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
314 for (; aSIt != aSLast; aSIt++) {
315 anOwnersToSelect.Clear();
316 getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
318 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
320 // restore the previous selection: end
322 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
323 aDisplayer->updateViewer();
330 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
332 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
333 if (aOperation && aOperation->isEditOperation()) {
334 std::string aId = aOperation->id().toStdString();
335 if ((aId == SketchPlugin_ConstraintLength::ID()) ||
336 (aId == SketchPlugin_ConstraintDistance::ID()) ||
337 (aId == SketchPlugin_ConstraintRadius::ID()))
339 // Activate dimension value editing on double click
340 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
341 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
342 // Find corresponded widget to activate value editing
343 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
344 if (aWgt->attributeID() == "ConstraintValue") {
353 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
354 double& theX, double& theY)
356 Handle(V3d_View) aView = theWnd->v3dView();
357 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
358 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
361 void PartSet_SketcherMgr::launchEditing()
363 // there should be activate the vertex selection mode because the edit can happens by the selected
366 aModes << TopAbs_VERTEX << TopAbs_EDGE;
367 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
368 aConnector->activateSubShapesSelection(aModes);
370 if (!myFeature2AttributeMap.empty()) {
371 FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
372 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
373 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
375 myModule->editFeature(aSPFeature);
382 QStringList PartSet_SketcherMgr::sketchOperationIdList()
384 static QStringList aIds;
385 if (aIds.size() == 0) {
386 aIds << SketchPlugin_Line::ID().c_str();
387 aIds << SketchPlugin_Point::ID().c_str();
388 aIds << SketchPlugin_Arc::ID().c_str();
389 aIds << SketchPlugin_Circle::ID().c_str();
390 aIds << SketchPlugin_ConstraintLength::ID().c_str();
391 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
392 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
393 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
394 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
395 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
400 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
402 // Display all sketcher sub-Objects
403 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
404 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
405 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
407 // Hide sketcher result
408 std::list<ResultPtr> aResults = myCurrentSketch->results();
409 std::list<ResultPtr>::const_iterator aIt;
410 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
411 aDisplayer->erase((*aIt), false);
413 aDisplayer->erase(myCurrentSketch, false);
415 // Display sketcher objects
416 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
417 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
418 std::list<ResultPtr> aResults = aFeature->results();
419 std::list<ResultPtr>::const_iterator aIt;
420 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
421 aDisplayer->display((*aIt), false);
423 aDisplayer->display(aFeature, false);
426 if (myPlaneFilter.IsNull())
427 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
429 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
430 if (theOperation->isEditOperation()) {
431 // If it is editing of sketch then it means that plane is already defined
432 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
433 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
435 aDisplayer->updateViewer();
438 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
440 DataPtr aData = myCurrentSketch->data();
441 if ((!aData) || (!aData->isValid())) {
442 // The sketch was aborted
443 myCurrentSketch = CompositeFeaturePtr();
444 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
447 // Hide all sketcher sub-Objects
448 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
449 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
450 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
451 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
452 std::list<ResultPtr> aResults = aFeature->results();
453 std::list<ResultPtr>::const_iterator aIt;
454 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
455 aDisplayer->erase((*aIt), false);
457 aDisplayer->erase(aFeature, false);
459 // Display sketcher result
460 std::list<ResultPtr> aResults = myCurrentSketch->results();
461 std::list<ResultPtr>::const_iterator aIt;
462 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
463 aDisplayer->display((*aIt), false);
465 aDisplayer->display(myCurrentSketch);
467 myCurrentSketch = CompositeFeaturePtr();
468 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
469 aDisplayer->updateViewer();
473 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
475 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
478 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
479 const FeaturePtr& theSketch,
480 ModuleBase_IWorkshop* theWorkshop,
481 FeatureToSelectionMap& theSelection)
482 //std::set<AttributePtr>& theSelectedAttributes,
483 //std::set<ResultPtr>& theSelectedResults)
485 if (theFeature.get() == NULL)
488 std::set<AttributePtr> aSelectedAttributes;
489 std::set<ResultPtr> aSelectedResults;
491 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
492 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
493 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
494 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
496 std::list<ResultPtr> aResults = theFeature->results();
497 std::list<ResultPtr>::const_iterator aIt;
498 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
500 ResultPtr aResult = *aIt;
501 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
502 if (aAISObj.get() == NULL)
504 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
505 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
507 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
508 aContext->SelectedOwner());
509 if (aBRepOwner.IsNull())
511 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
512 aBRepOwner->Selectable());
513 if (aBRepOwner->HasShape()) {
514 const TopoDS_Shape& aShape = aBRepOwner->Shape();
515 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
516 if (aShapeType == TopAbs_VERTEX) {
517 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
519 if (aPntAttr.get() != NULL)
520 aSelectedAttributes.insert(aPntAttr);
522 else if (aShapeType == TopAbs_EDGE &&
523 aSelectedResults.find(aResult) == aSelectedResults.end()) {
524 aSelectedResults.insert(aResult);
529 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
532 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
533 const FeaturePtr& theSketch,
534 ModuleBase_IWorkshop* theWorkshop,
535 //const std::set<AttributePtr>& theSelectedAttributes,
536 //const std::set<ResultPtr>& theSelectedResults,
537 const FeatureToSelectionMap& theSelection,
538 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
540 if (theFeature.get() == NULL)
543 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
544 std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
545 std::set<ResultPtr> aSelectedResults = anIt->second.second;
547 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
548 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
549 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
550 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
552 std::list<ResultPtr> aResults = theFeature->results();
553 std::list<ResultPtr>::const_iterator aIt;
554 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
556 ResultPtr aResult = *aIt;
557 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
558 if (aAISObj.get() == NULL)
560 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
562 SelectMgr_IndexedMapOfOwner aSelectedOwners;
563 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
564 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
565 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
566 if ( anOwner.IsNull() || !anOwner->HasShape() )
568 const TopoDS_Shape& aShape = anOwner->Shape();
569 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
570 if (aShapeType == TopAbs_VERTEX) {
571 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
572 if (aPntAttr.get() != NULL &&
573 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
574 anOwnersToSelect.Add(anOwner);
577 else if (aShapeType == TopAbs_EDGE) {
578 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
579 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
580 anOwnersToSelect.FindIndex(anOwner) <= 0)
581 anOwnersToSelect.Add(anOwner);