<commit_before>/***************************************************************************
 *   Copyright (c) <NAME> (<EMAIL>) 2014              *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 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 Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/


#include "PreCompiled.h"

#ifndef _PreComp_
# include <Python.h>
# include <Inventor/SbVec3f.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoTransform.h>
# include <Inventor/nodes/SoRotation.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoMaterial.h>
# include <Inventor/nodes/SoMaterialBinding.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoPointSet.h>
# include <Inventor/nodes/SoShapeHints.h>
# include <Inventor/details/SoLineDetail.h>
# include <Inventor/nodes/SoSwitch.h>
# include <Inventor/nodes/SoAnnotation.h>
# include <QFile>
#endif

#include <boost/algorithm/string/replace.hpp>

#include "ViewProviderPath.h"

#include <Mod/Path/App/FeaturePath.h>
#include <Mod/Path/App/Path.h>
#include <Mod/Path/App/PathSegmentWalker.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Base/FileInfo.h>
#include <Base/Stream.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/SoFCBoundingBox.h>
#include <Gui/SoAxisCrossKit.h>
#include <Gui/SoFCUnifiedSelection.h>

using namespace Gui;
using namespace PathGui;
using namespace Path;
using namespace PartGui;

namespace PathGui {

class PathSelectionObserver: public Gui::SelectionObserver {
public:
    static void init() {
        static PathSelectionObserver *instance;
        if(!instance)
            instance = new PathSelectionObserver();
    }

    void setArrow(SoSwitch *pcSwitch=0) {
        if(pcSwitch==pcLastArrowSwitch)
            return;
        if(pcLastArrowSwitch) {
            pcLastArrowSwitch->whichChild = -1;
            pcLastArrowSwitch->unref();
            pcLastArrowSwitch = 0;
        }
        if(pcSwitch) {
            pcSwitch->ref();
            pcSwitch->whichChild = 0;
            pcLastArrowSwitch = pcSwitch;
        }
    }

    void onSelectionChanged(const Gui::SelectionChanges& msg) {
        if(msg.Type == Gui::SelectionChanges::RmvPreselect) {
            setArrow();
            return;
        }
        if(msg.Type!=Gui::SelectionChanges::SetPreselect 
                    && msg.Type!=Gui::SelectionChanges::MovePreselect)
            return;
        auto obj = msg.Object.getObject();
        if(!obj)
            return;
        Base::Matrix4D mat;
        auto sobj = obj->getSubObject(msg.pSubName,0,&mat);
        if(!sobj)
            return;
        Base::Matrix4D linkMat;
        auto linked = sobj->getLinkedObject(true,&linkMat,false);
        auto vp = Base::freecad_dynamic_cast<ViewProviderPath>(
                        Application::Instance->getViewProvider(linked));
        if(!vp) {
            setArrow();
            return;
        }
        
        if(vp->pt0Index >= 0) { 
            mat *= linkMat;
            mat.inverse();
            Base::Vector3d pt = mat*Base::Vector3d(msg.x,msg.y,msg.z);
            auto ptTo = vp->pcLineCoords->point.getValues(vp->pt0Index);
            SbVec3f ptFrom(pt.x,pt.y,pt.z);
            if(ptTo && ptFrom != *ptTo) {
                vp->pcArrowTransform->pointAt(ptFrom,*ptTo);
                setArrow(vp->pcArrowSwitch);
                return;
            }
        }
        setArrow();<commit_msg>check if pcLineCoords is empty<commit_after>/***************************************************************************
 *   Copyright (c) <NAME> (<EMAIL>) 2014              *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 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 Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/


#include "PreCompiled.h"

#ifndef _PreComp_
# include <Python.h>
# include <Inventor/SbVec3f.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoTransform.h>
# include <Inventor/nodes/SoRotation.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoMaterial.h>
# include <Inventor/nodes/SoMaterialBinding.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoIndexedLineSet.h>
# include <Inventor/nodes/SoPointSet.h>
# include <Inventor/nodes/SoShapeHints.h>
# include <Inventor/details/SoLineDetail.h>
# include <Inventor/nodes/SoSwitch.h>
# include <Inventor/nodes/SoAnnotation.h>
# include <QFile>
#endif

#include <boost/algorithm/string/replace.hpp>

#include "ViewProviderPath.h"

#include <Mod/Path/App/FeaturePath.h>
#include <Mod/Path/App/Path.h>
#include <Mod/Path/App/PathSegmentWalker.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Base/FileInfo.h>
#include <Base/Stream.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/SoFCBoundingBox.h>
#include <Gui/SoAxisCrossKit.h>
#include <Gui/SoFCUnifiedSelection.h>

using namespace Gui;
using namespace PathGui;
using namespace Path;
using namespace PartGui;

namespace PathGui {

class PathSelectionObserver: public Gui::SelectionObserver {
public:
    static void init() {
        static PathSelectionObserver *instance;
        if(!instance)
            instance = new PathSelectionObserver();
    }

    void setArrow(SoSwitch *pcSwitch=0) {
        if(pcSwitch==pcLastArrowSwitch)
            return;
        if(pcLastArrowSwitch) {
            pcLastArrowSwitch->whichChild = -1;
            pcLastArrowSwitch->unref();
            pcLastArrowSwitch = 0;
        }
        if(pcSwitch) {
            pcSwitch->ref();
            pcSwitch->whichChild = 0;
            pcLastArrowSwitch = pcSwitch;
        }
    }

    void onSelectionChanged(const Gui::SelectionChanges& msg) {
        if(msg.Type == Gui::SelectionChanges::RmvPreselect) {
            setArrow();
            return;
        }
        if(msg.Type!=Gui::SelectionChanges::SetPreselect 
                    && msg.Type!=Gui::SelectionChanges::MovePreselect)
            return;
        auto obj = msg.Object.getObject();
        if(!obj)
            return;
        Base::Matrix4D mat;
        auto sobj = obj->getSubObject(msg.pSubName,0,&mat);
        if(!sobj)
            return;
        Base::Matrix4D linkMat;
        auto linked = sobj->getLinkedObject(true,&linkMat,false);
        auto vp = Base::freecad_dynamic_cast<ViewProviderPath>(
                        Application::Instance->getViewProvider(linked));
        if(!vp) {
            setArrow();
            return;
        }
        
        if(vp->pt0Index >= 0) { 
            mat *= linkMat;
            mat.inverse();
            Base::Vector3d pt = mat*Base::Vector3d(msg.x,msg.y,msg.z);
            if(vp->pcLineCoords->point.getNum() > 0){
                auto ptTo = vp->pcLineCoords->point.getValues(vp->pt0Index);
                SbVec3f ptFrom(pt.x,pt.y,pt.z);
                if(ptTo && ptFrom != *ptTo) {
                    vp->pcArrowTransform->pointAt(ptFrom,*ptTo);
                    setArrow(vp->pcArrowSwitch);
                    return;
                }
            }
        }
        setArrow();
{'fraction_non_alphanumeric': 0.13233383308345828, 'fraction_numerical': 0.006896551724137931, 'mean_word_length': 1.9603550295857988, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1066354', 'n_tokens_mistral': 2795, 'n_tokens_neox': 2727, 'n_words': 621}