2015-07-29 14:19:43 +02:00
|
|
|
//##################################################################################################
|
|
|
|
|
//
|
|
|
|
|
// Custom Visualization Core library
|
|
|
|
|
// Copyright (C) 2011-2013 Ceetron AS
|
|
|
|
|
//
|
|
|
|
|
// This library may be used under the terms of either the GNU General Public License or
|
|
|
|
|
// the GNU Lesser General Public License as follows:
|
|
|
|
|
//
|
|
|
|
|
// GNU General Public License Usage
|
|
|
|
|
// This library is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
|
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
// GNU Lesser General Public License Usage
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
//
|
|
|
|
|
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
|
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
//##################################################################################################
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-06-27 13:15:20 +02:00
|
|
|
#include "cafSelectionChangedReceiver.h"
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-06-27 13:15:20 +02:00
|
|
|
#include "cafPdmPointer.h"
|
2015-07-29 14:19:43 +02:00
|
|
|
#include "cafPdmField.h"
|
|
|
|
|
|
|
|
|
|
#include <QString>
|
2018-06-27 13:15:20 +02:00
|
|
|
#include <vector>
|
|
|
|
|
#include <set>
|
2015-07-29 14:19:43 +02:00
|
|
|
|
|
|
|
|
namespace caf
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class PdmUiItem;
|
|
|
|
|
class NotificationCenter;
|
|
|
|
|
class PdmChildArrayFieldHandle;
|
|
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
|
///
|
|
|
|
|
//==================================================================================================
|
|
|
|
|
class SelectionManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-08-21 15:49:44 +02:00
|
|
|
enum SelectionLevel
|
|
|
|
|
{
|
|
|
|
|
UNDEFINED = -1,
|
|
|
|
|
BASE_LEVEL = 0,
|
|
|
|
|
FIRST_LEVEL = 1,
|
|
|
|
|
SECOND_LEVEL = 2
|
2015-07-29 14:19:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
2018-06-28 09:58:07 +02:00
|
|
|
static SelectionManager* instance();
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-06-28 09:58:07 +02:00
|
|
|
// OBSOLETE ! Remove when time to refactor the command system
|
|
|
|
|
NotificationCenter* notificationCenter();
|
|
|
|
|
|
|
|
|
|
void setActiveChildArrayFieldHandle(PdmChildArrayFieldHandle* childArray);
|
|
|
|
|
PdmChildArrayFieldHandle* activeChildArrayFieldHandle();
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-06-28 09:58:07 +02:00
|
|
|
void setPdmRootObject(PdmObjectHandle* root);
|
|
|
|
|
PdmObjectHandle* pdmRootObject() { return m_rootObject; }
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-08-21 15:05:49 +02:00
|
|
|
PdmUiItem* selectedItem(int selectionLevel = 0);
|
|
|
|
|
void setSelectedItem(PdmUiItem* item, int selectionLevel = 0);
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-08-21 15:05:49 +02:00
|
|
|
void selectedItems(std::vector<PdmUiItem*>& items, int selectionLevel = 0);
|
|
|
|
|
void setSelectedItems(const std::vector<PdmUiItem*>& items, int selectionLevel = 0);
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-08-21 15:05:49 +02:00
|
|
|
void selectionAsReferences(std::vector<QString>& referenceList, int selectionLevel = 0) const;
|
|
|
|
|
void setSelectionFromReferences(const std::vector<QString>& referenceList, int selectionLevel = 0);
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-06-28 09:58:07 +02:00
|
|
|
void clearAll();
|
2018-08-21 15:05:49 +02:00
|
|
|
void clear(int selectionLevel);
|
2018-06-28 09:58:07 +02:00
|
|
|
void removeObjectFromAllSelections(PdmObjectHandle* pdmObject);
|
2015-07-29 14:19:43 +02:00
|
|
|
|
|
|
|
|
template <typename T>
|
2018-08-21 15:05:49 +02:00
|
|
|
void objectsByType(std::vector<T*>* typedObjects, int selectionLevel = 0)
|
2015-07-29 14:19:43 +02:00
|
|
|
{
|
|
|
|
|
std::vector<PdmUiItem*> items;
|
2018-08-21 15:05:49 +02:00
|
|
|
this->selectedItems(items, selectionLevel);
|
2015-07-29 14:19:43 +02:00
|
|
|
for (size_t i = 0; i < items.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
T* obj = dynamic_cast<T*>(items[i]);
|
|
|
|
|
if (obj) typedObjects->push_back(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-27 13:15:20 +02:00
|
|
|
|
|
|
|
|
/// Returns the selected objects of the requested type if _all_ the selected objects are of the requested type
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-05-07 09:44:38 +02:00
|
|
|
template <typename T>
|
2018-08-21 15:05:49 +02:00
|
|
|
void objectsByTypeStrict(std::vector<T*>* typedObjects, int selectionLevel = 0)
|
2018-05-07 09:44:38 +02:00
|
|
|
{
|
|
|
|
|
std::vector<PdmUiItem*> items;
|
2018-08-21 15:05:49 +02:00
|
|
|
this->selectedItems(items, selectionLevel);
|
2018-05-07 09:44:38 +02:00
|
|
|
for (size_t i = 0; i < items.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
T* obj = dynamic_cast<T*>(items[i]);
|
|
|
|
|
if (!obj)
|
|
|
|
|
{
|
|
|
|
|
typedObjects->clear();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
typedObjects->push_back(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-29 14:19:43 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
SelectionManager();
|
2018-06-28 09:58:07 +02:00
|
|
|
|
2018-08-21 13:41:56 +02:00
|
|
|
void notifySelectionChanged( int selectionLevel);
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-06-27 13:15:20 +02:00
|
|
|
friend class SelectionChangedReceiver;
|
|
|
|
|
void registerSelectionChangedReceiver ( SelectionChangedReceiver* receiver) { m_selectionReceivers.insert(receiver);}
|
|
|
|
|
void unregisterSelectionChangedReceiver( SelectionChangedReceiver* receiver) { m_selectionReceivers.erase(receiver);}
|
|
|
|
|
|
2015-07-29 14:19:43 +02:00
|
|
|
private:
|
2018-08-21 15:05:49 +02:00
|
|
|
std::map <int, std::vector< std::pair<PdmPointer<PdmObjectHandle>, PdmUiItem*> > > m_selectionPrLevel;
|
2015-07-29 14:19:43 +02:00
|
|
|
|
|
|
|
|
PdmChildArrayFieldHandle* m_activeChildArrayFieldHandle;
|
|
|
|
|
PdmPointer<PdmObjectHandle> m_rootObject;
|
2018-06-27 13:15:20 +02:00
|
|
|
|
|
|
|
|
std::set< SelectionChangedReceiver*> m_selectionReceivers;
|
2015-07-29 14:19:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace caf
|