<commit_before>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4      *
*                (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* This program 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 2 of the License, or (at your option)   *
* any later version.                                                          *
*                                                                             *
* This program 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 for    *
* more details.                                                               *
*                                                                             *
* You should have received a copy of the GNU General Public License along     *
* with this program; if not, write to the Free Software Foundation, Inc., 51  *
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                   *
*******************************************************************************
*                            SOFA :: Applications                             *
*                                                                             *
* Authors: <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>,*
* <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>,  *
* <NAME>, <NAME>, J-P. de la Plata Alcade, <NAME> and <NAME>          *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#include "SofaModeler.h"
#include <sofa/helper/system/FileRepository.h>
#include <sofa/helper/system/SetDirectory.h>
#include <sofa/simulation/tree/TreeSimulation.h>

#define MAX_RECENTLY_OPENED 10


#include <map>
#include <set>
#include <cstdio>


//Automatically create and destroy all the components available: easy way to verify the default constructor and destructor
//#define TEST_CREATION_COMPONENT

#ifdef SOFA_QT4
#include <QToolBox>
#include <QSpacerItem>
#include <QGridLayout>
#include <QTextEdit>
#include <Q3TextBrowser>
#include <QLabel>
#include <QApplication>
#include <QMenuBar>
#include <QMessageBox>
#include <QDir>
#include <QStatusBar>
#else
#include <qtoolbox.h>
#include <qlayout.h>
#include <qtextedit.h>
#include <qtextbrowser.h>
#include <qapplication.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qdir.h>
#include <qstatusbar.h>
#endif

namespace sofa
{

namespace gui
{

namespace qt
{

#ifndef SOFA_QT4
typedef QTextDrag Q3TextDrag;
#endif


SofaModeler::SofaModeler()
{
    //index to add in temporary scenes created by the Modeler
    count='0';
    isPasteReady=false;
    editPasteAction->setEnabled(false);
#ifdef SOFA_QT4
    fileMenu->removeAction(Action);
#endif


    //----------------------------------------------------------------------
    //Get the different path needed
    examplePath = sofa::helper::system::SetDirectory::GetParentDir(sofa::helper::system::DataRepository.getFirstPath().c_str()) + std::string( "/examples/" );
    binPath = sofa::helper::system::SetDirectory::GetParentDir(sofa::helper::system::DataRepository.getFirstPath().c_str()) + std::string( "/bin/" );
    presetPath = examplePath + std::string("Objects/");
    std::string presetFile = std::string("config/preset.ini" );
    presetFile = sofa::helper::system::DataRepository.getFile ( presetFile );



    //Find all the scene files in examples directory
    std::vector< QString > exampleQString;
    std::vector< QString > filter;
    const QString path(examplePath.c_str());
    filter.push_back("*.scn"); filter.push_back("*.xml");
    sofa::gui::qt::getFilesInDirectory(path, exampleQString, true, filter);



    //----------------------------------------------------------------------
    // Create the Left part of the GUI
    //----------------------------------------------------------------------
    QWidget *leftPartWidget = new QWidget( (QWidget*)splitter2, "LibraryLayout");
    QVBoxLayout *leftPartLayout = new QVBoxLayout(leftPartWidget);

    //----------------------------------------------------------------------
    //Add the button to create GNode
    QPushButton *GNodeButton = new QPushButton( leftPartWidget, "GNodeButton");
    GNodeButton->setText("GNode");
    leftPartLayout->addWidget(GNodeButton);
    connect( GNodeButton, SIGNAL( pressed() ),  this, SLOT( pressedGNodeButton() ) );

    //----------------------------------------------------------------------
    //Add a Filter to the Library
    QWidget *filterContainer = new QWidget( leftPartWidget, "filterContainer" );
    QHBoxLayout *filterLayout = new QHBoxLayout(filterContainer);
    leftPartLayout->addWidget(filterContainer);
    //--> Label
    QLabel *filterLabel = new QLabel(filterContainer, "filterLabel");
    filterLabel->setText( "Filter: " );
    filterLayout->addWidget(filterLabel);
    //--> Filter
    filterLibrary = new FilterLibrary(filterContainer);
    filterLayout->addWidget(filterLibrary);
    connect(filterLibrary, SIGNAL( filterList( const FilterQuery &) ), this, SLOT(searchText( const FilterQuery &)) );


    //----------------------------------------------------------------------
    //Add the Sofa Library
    //-->Container
    containerLibrary = new QToolBox( leftPartWidget, "containerLibrary");
    containerLibrary->setCurrentIndex(1);
    containerLibrary->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);

    QWidget *contentContainer = new QWidget( containerLibrary, "contentContainer");
    QVBoxLayout *contentLayout = new QVBoxLayout( contentContainer );
    containerLibrary->addItem(contentContainer, QString());
    leftPartLayout->addWidget(containerLibrary);


    //-->Sofa Library
    QSofaLibrary *l = new QSofaLibrary(contentContainer); library = l;
    QToolBox *containerLibrary=l->getContainer();
    contentLayout->addWidget(containerLibrary);
    connect(l, SIGNAL( componentDragged( std::string, std::string, std::string, ClassEntry *) ),
            this, SLOT( componentDraggedReception( std::string, std::string, std::string, ClassEntry *) ));

    for (unsigned int i=0; i<exampleQString.size(); ++i) exampleFiles.push_back(exampleQString[i].ascii());
    library->build(exampleFiles);
    changeLibraryLabel(0);



    //----------------------------------------------------------------------
    // Create the Right part of the GUI
    //----------------------------------------------------------------------

    //----------------------------------------------------------------------
    //Create the scene graph visualization
    QWidget *GraphSupport = new QWidget((QWidget*)splitter2);
    QGridLayout* GraphLayout = new QGridLayout(GraphSupport, 1,1,5,2,"GraphLayout");
    sceneTab = new QTabWidget(GraphSupport);
    GraphLayout->addWidget(sceneTab,0,0);
    connect( sceneTab, SIGNAL(currentChanged( QWidget*)), this, SLOT( changeCurrentScene( QWidget*)));

    GraphSupport->resize(200,550);

    //----------------------------------------------------------------------
    //Add plugin manager window. ->load external libs
    pluginManager = new SofaPluginManager;
    pluginManager->hide();
    this->connect(pluginManager->buttonClose, SIGNAL(clicked() ),  this, SLOT( rebuildLibrary() ));

    int menuIndex=4;

    //----------------------------------------------------------------------
    // Create the Menus
    //----------------------------------------------------------------------

    //----------------------------------------------------------------------
    //Add menu runSofa
    Q3PopupMenu *runSofaMenu = new Q3PopupMenu(this);
    this->menubar->insertItem(tr(QString("&RunSofa")), runSofaMenu, menuIndex++);

    runInSofaAction->addTo(runSofaMenu);<commit_msg>r5034/sofa-dev : FIX : bug in modeler, component list initialization done after plugins loading<commit_after>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4      *
*                (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* This program 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 2 of the License, or (at your option)   *
* any later version.                                                          *
*                                                                             *
* This program 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 for    *
* more details.                                                               *
*                                                                             *
* You should have received a copy of the GNU General Public License along     *
* with this program; if not, write to the Free Software Foundation, Inc., 51  *
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                   *
*******************************************************************************
*                            SOFA :: Applications                             *
*                                                                             *
* Authors: <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>,*
* <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>,  *
* <NAME>, <NAME>, <NAME>, <NAME> and <NAME>          *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#include "SofaModeler.h"
#include <sofa/helper/system/FileRepository.h>
#include <sofa/helper/system/SetDirectory.h>
#include <sofa/simulation/tree/TreeSimulation.h>

#define MAX_RECENTLY_OPENED 10


#include <map>
#include <set>
#include <cstdio>


//Automatically create and destroy all the components available: easy way to verify the default constructor and destructor
//#define TEST_CREATION_COMPONENT

#ifdef SOFA_QT4
#include <QToolBox>
#include <QSpacerItem>
#include <QGridLayout>
#include <QTextEdit>
#include <Q3TextBrowser>
#include <QLabel>
#include <QApplication>
#include <QMenuBar>
#include <QMessageBox>
#include <QDir>
#include <QStatusBar>
#else
#include <qtoolbox.h>
#include <qlayout.h>
#include <qtextedit.h>
#include <qtextbrowser.h>
#include <qapplication.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qdir.h>
#include <qstatusbar.h>
#endif

namespace sofa
{

namespace gui
{

namespace qt
{

#ifndef SOFA_QT4
typedef QTextDrag Q3TextDrag;
#endif


SofaModeler::SofaModeler()
{
    //index to add in temporary scenes created by the Modeler
    count='0';
    isPasteReady=false;
    editPasteAction->setEnabled(false);
#ifdef SOFA_QT4
    fileMenu->removeAction(Action);
#endif


    //----------------------------------------------------------------------
    //Get the different path needed
    examplePath = sofa::helper::system::SetDirectory::GetParentDir(sofa::helper::system::DataRepository.getFirstPath().c_str()) + std::string( "/examples/" );
    binPath = sofa::helper::system::SetDirectory::GetParentDir(sofa::helper::system::DataRepository.getFirstPath().c_str()) + std::string( "/bin/" );
    presetPath = examplePath + std::string("Objects/");
    std::string presetFile = std::string("config/preset.ini" );
    presetFile = sofa::helper::system::DataRepository.getFile ( presetFile );



    //Find all the scene files in examples directory
    std::vector< QString > exampleQString;
    std::vector< QString > filter;
    const QString path(examplePath.c_str());
    filter.push_back("*.scn"); filter.push_back("*.xml");
    sofa::gui::qt::getFilesInDirectory(path, exampleQString, true, filter);



    //----------------------------------------------------------------------
    // Create the Left part of the GUI
    //----------------------------------------------------------------------
    QWidget *leftPartWidget = new QWidget( (QWidget*)splitter2, "LibraryLayout");
    QVBoxLayout *leftPartLayout = new QVBoxLayout(leftPartWidget);

    //----------------------------------------------------------------------
    //Add the button to create GNode
    QPushButton *GNodeButton = new QPushButton( leftPartWidget, "GNodeButton");
    GNodeButton->setText("GNode");
    leftPartLayout->addWidget(GNodeButton);
    connect( GNodeButton, SIGNAL( pressed() ),  this, SLOT( pressedGNodeButton() ) );

    //----------------------------------------------------------------------
    //Add a Filter to the Library
    QWidget *filterContainer = new QWidget( leftPartWidget, "filterContainer" );
    QHBoxLayout *filterLayout = new QHBoxLayout(filterContainer);
    leftPartLayout->addWidget(filterContainer);
    //--> Label
    QLabel *filterLabel = new QLabel(filterContainer, "filterLabel");
    filterLabel->setText( "Filter: " );
    filterLayout->addWidget(filterLabel);
    //--> Filter
    filterLibrary = new FilterLibrary(filterContainer);
    filterLayout->addWidget(filterLibrary);
    connect(filterLibrary, SIGNAL( filterList( const FilterQuery &) ), this, SLOT(searchText( const FilterQuery &)) );


    //----------------------------------------------------------------------
    //Add the Sofa Library
    //-->Container
    containerLibrary = new QToolBox( leftPartWidget, "containerLibrary");
    containerLibrary->setCurrentIndex(1);
    containerLibrary->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);

    QWidget *contentContainer = new QWidget( containerLibrary, "contentContainer");
    QVBoxLayout *contentLayout = new QVBoxLayout( contentContainer );
    containerLibrary->addItem(contentContainer, QString());
    leftPartLayout->addWidget(containerLibrary);


    //-->Sofa Library
    QSofaLibrary *l = new QSofaLibrary(contentContainer); library = l;
    QToolBox *containerLibrary=l->getContainer();
    contentLayout->addWidget(containerLibrary);
    connect(l, SIGNAL( componentDragged( std::string, std::string, std::string, ClassEntry *) ),
            this, SLOT( componentDraggedReception( std::string, std::string, std::string, ClassEntry *) ));

    for (unsigned int i=0; i<exampleQString.size(); ++i) exampleFiles.push_back(exampleQString[i].ascii());

    changeLibraryLabel(0);



    //----------------------------------------------------------------------
    // Create the Right part of the GUI
    //----------------------------------------------------------------------

    //----------------------------------------------------------------------
    //Create the scene graph visualization
    QWidget *GraphSupport = new QWidget((QWidget*)splitter2);
    QGridLayout* GraphLayout = new QGridLayout(GraphSupport, 1,1,5,2,"GraphLayout");
    sceneTab = new QTabWidget(GraphSupport);
    GraphLayout->addWidget(sceneTab,0,0);
    connect( sceneTab, SIGNAL(currentChanged( QWidget*)), this, SLOT( changeCurrentScene( QWidget*)));

    GraphSupport->resize(200,550);

    //----------------------------------------------------------------------
    //Add plugin manager window. ->load external libs
    pluginManager = new SofaPluginManager;
    pluginManager->hide();
    this->connect(pluginManager->buttonClose, SIGNAL(clicked() ),  this, SLOT( rebuildLibrary() ));

    library->build(exampleFiles);

    int menuIndex=4;

    //----------------------------------------------------------------------
    // Create the Menus
    //----------------------------------------------------------------------

    //----------------------------------------------------------------------
    //Add menu runSofa
    Q3PopupMenu *runSofaMenu = new Q3PopupMenu(this);
    this->menubar->insertItem(tr(QString("&RunSofa")), runSofaMenu, menuIndex++);

    runInSofaAction->addTo(runSofaMenu);
{'fraction_non_alphanumeric': 0.24157133345439138, 'fraction_numerical': 0.006416076508685915, 'mean_word_length': 1.983387504514265, 'pattern_counts': {'":': 0, '<': 96, '<?xml version=': 0, '>': 150, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1881570', 'n_tokens_mistral': 4184, 'n_tokens_neox': 4001, 'n_words': 1038}