<commit_before>// $RCSfile: $
// $Revision: $ $Date: $
// Auth: <NAME> (<EMAIL>)
// 
// Copyright (c) 1991-2016 by STEP Tools Inc. 
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "nodeFinder.h"
#include "nodeUtils.h"
Finder *Finder::_singleton = nullptr;

NAN_METHOD(Finder::New)
{
	if (info.IsConstructCall())
	{
		if (!info[0]->IsUndefined())
		{
			return;
		}
		if (_singleton == nullptr)
			_singleton = new Finder();
		_singleton->Wrap(info.This());
		info.GetReturnValue().Set(info.This());
	}
	else
	{
		return;
	}
}

NAN_MODULE_INIT(Finder::Init)
{
	v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
	tpl->SetClassName(Nan::New("Finder").ToLocalChecked());
	tpl->InstanceTemplate()->SetInternalFieldCount(1);
	Nan::SetPrototypeMethod(tpl, "APIUnitsInch", APIUnitsInch);
	Nan::SetPrototypeMethod(tpl, "APIUnitsMM", APIUnitsMM);
	Nan::SetPrototypeMethod(tpl, "APIUnitsNative", APIUnitsNative);
	Nan::SetPrototypeMethod(tpl, "APIUnitsFeed", APIUnitsFeed);
	Nan::SetPrototypeMethod(tpl, "APIUnitsSpeed", APIUnitsSpeed);
	Nan::SetPrototypeMethod(tpl, "GetCompoundFeatureCount", GetCompoundFeatureCount);
	Nan::SetPrototypeMethod(tpl, "GetExecutableDistance", GetExecutableDistance);
	Nan::SetPrototypeMethod(tpl, "GetExecutableDistanceUnit", GetExecutableDistanceUnit);
	Nan::SetPrototypeMethod(tpl, "GetExecutableName", GetExecutableName);
	Nan::SetPrototypeMethod(tpl, "GetExecutableWorkpieceRemoval", GetExecutableWorkpieceRemoval);
	Nan::SetPrototypeMethod(tpl, "GetFaceEdgeCount", GetFaceEdgeCount);
	Nan::SetPrototypeMethod(tpl, "GetFaceEdgeNextPoint", GetFaceEdgeCount);
	Nan::SetPrototypeMethod(tpl, "GetFeatureID", GetFeatureID);
	Nan::SetPrototypeMethod(tpl, "GetFeatureName", GetFeatureName);
	Nan::SetPrototypeMethod(tpl, "GetFeatureOutsideProfileClosedCircular", GetFeatureOutsideProfileClosedCircular);
	Nan::SetPrototypeMethod(tpl, "GetMainWorkplan", GetMainWorkplan);
	Nan::SetPrototypeMethod(tpl, "GetProcessFeed", GetProcessFeed);
	Nan::SetPrototypeMethod(tpl, "GetProcessFeedUnit", GetProcessFeedUnit);
	Nan::SetPrototypeMethod(tpl, "GetProjectName", GetProjectName);
	Nan::SetPrototypeMethod(tpl, "IsSelective", IsSelective);
	Nan::SetPrototypeMethod(tpl, "IsWorkingstep", IsWorkingstep);
	Nan::SetPrototypeMethod(tpl, "OpenProject", OpenProject);
	Nan::SetPrototypeMethod(tpl, "SaveAsModules", SaveAsModules);
	Nan::SetPrototypeMethod(tpl, "SaveAsP21", SaveAsP21);
	constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked());
	Nan::Set(target, Nan::New("Finder").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
}

NAN_METHOD(Finder::APIUnitsFeed) {
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (!find) //Throw Exception
	return;
    if (info.Length() != 1) //Function takes one argument
	return;
    if (info[0]->IsUndefined()) //Argument should exist
	return;
    if (!info[0]->IsString()) //Throw Exception
	return;
    char * b;
    size_t len = v8StringToChar(info[0], b);
    if (!find->_find->api_unit_feed(b)) //Throw Exception
	return;
    delete[] b;
}
NAN_METHOD(Finder::APIUnitsInch) {

    Finder * find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) {
	return; // Throw Exception
    }
    if (!(info[0]->IsUndefined())) { // function has 0 arguements
	return; //Throw Exeption
    }
    if (!find->_find->api_unit_inch()) {
	return; //throw error
    }
    return;

}

NAN_METHOD(Finder::APIUnitsMM) {

    Finder * find = Nan::ObjectWrap::Unwrap<Finder>(info.This());

    if (find == 0) {
	return; // Throw Exception
    }
    if (!(info[0]->IsUndefined())) { // function has 0 arguements
	return; //Throw Exeption
    }
    if (!find->_find->api_unit_mm()) {
	return; //throw error
    }
    return;
}

NAN_METHOD(Finder::APIUnitsNative) {

    Finder * find = Nan::ObjectWrap::Unwrap<Finder>(info.This());

    if (find == 0) {
	return; // Throw Exception
    }
    if (!(info[0]->IsUndefined())) { // function has 0 arguements
	return; //Throw Exeption
    }
    if (!find->_find->api_unit_native()) {
	return; //throw error
    }
    return;
}

NAN_METHOD(Finder::APIUnitsSpeed) {
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (!find) //Throw Exception
	return;
    if (info.Length() != 1) //Function takes one argument
	return;
    if (info[0]->IsUndefined()) //Argument should exist
	return;
    if (!info[0]->IsString()) //Throw Exception
	return;
    char * b;
    size_t len = v8StringToChar(info[0], b);
    if (!find->_find->api_unit_speed(b)) //Throw Exception
	return;
    delete[] b;
}



NAN_METHOD(Finder::GetCompoundFeatureCount) {

    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) {
	return; //Throw an exception
    }
    if (info.Length() != 1) { // Needs one argument
	return; // Throw an exception
    }
    if (!info[0]->IsInt32()) { // argument of wrong type
	return; //Throw exception
    }
    int size = 0;
    int feature_id = 0;
    double x;
    double y;
    double z;

    if (!find->_find->first_feature_in_compound(info[0]->Int32Value(), feature_id, size, x, y, z)) {
	return; //throw Error
    }

    info.GetReturnValue().Set(size);
    return;
}

NAN_METHOD(Finder::GetExecutableDistance)
{
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) // Throw exception
	return;

    if (info.Length() != 1) // incorrect number of arguments
	return;

    if (!info[0]->IsNumber()) // invalid argument
	return;

    // get this executable's id
    int64_t exe_id = info[0]->IntegerValue();

    double distance = 0.0;
    double over_time, base_time;

    const char *str1, *str2;

    if (!find->_find->compute_best_feed_time(
	(int)exe_id, distance, base_time, over_time, str1, str2
	))	// cpp error
	return;

    info.GetReturnValue().Set(distance);
    return;
}

NAN_METHOD(Finder::GetExecutableDistanceUnit)
{
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) // Throw exception
	return;

    if (info.Length() != 1) // incorrect number of arguments
	return;

    if (!info[0]->IsNumber()) // invalid argument
	return;

    // get this executable's id
    int64_t exe_id = info[0]->IntegerValue();

    const char *dist_unit = 0;
    double over_time, base_time, distance;
    const char *str2;

    if (!find->_find->compute_best_feed_time(
	(int)exe_id, distance, base_time, over_time, dist_unit, str2
	))
	return;

    info.GetReturnValue().Set(CharTov8String((char*) dist_unit));

    return;
}

NAN_METHOD(Finder::GetExecutableName) {
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) // Throw exception
	return;

    if (info.Length() != 1) // incorrect number of arguments
	return;

    if (!info[0]->IsInt32()) // invalid argument
	return;

    const char * name = 0;
    Nan::Maybe<int32_t> t = Nan::To<int32_t>(info[0]);
    if (!find->_find->executable_name(t.FromJust(), name))
	return;

    info.GetReturnValue().Set(CharTov8String((char *)name));
    return;
}

NAN_METHOD(Finder::GetExecutableWorkpieceRemoval)
{
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) // Throw exception
	return;

    if (info.Length() != 1) // incorrect number of arguments
	return;

    long exe_id = info[0]->IntegerValue();

    int wp_id = 0;

    if (!find->_find->executable_removal_workpiece((int)exe_id, wp_id))    // error in cpp
	return;

    info.GetReturnValue().Set(wp_id);

    return;<commit_msg>Made Int32 conversion more portable in GetExecutableWorkpieceRemoval()<commit_after>// $RCSfile: $
// $Revision: $ $Date: $
// Auth: <NAME> (<EMAIL>)
// 
// Copyright (c) 1991-2016 by STEP Tools Inc. 
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "nodeFinder.h"
#include "nodeUtils.h"
Finder *Finder::_singleton = nullptr;

NAN_METHOD(Finder::New)
{
	if (info.IsConstructCall())
	{
		if (!info[0]->IsUndefined())
		{
			return;
		}
		if (_singleton == nullptr)
			_singleton = new Finder();
		_singleton->Wrap(info.This());
		info.GetReturnValue().Set(info.This());
	}
	else
	{
		return;
	}
}

NAN_MODULE_INIT(Finder::Init)
{
	v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
	tpl->SetClassName(Nan::New("Finder").ToLocalChecked());
	tpl->InstanceTemplate()->SetInternalFieldCount(1);
	Nan::SetPrototypeMethod(tpl, "APIUnitsInch", APIUnitsInch);
	Nan::SetPrototypeMethod(tpl, "APIUnitsMM", APIUnitsMM);
	Nan::SetPrototypeMethod(tpl, "APIUnitsNative", APIUnitsNative);
	Nan::SetPrototypeMethod(tpl, "APIUnitsFeed", APIUnitsFeed);
	Nan::SetPrototypeMethod(tpl, "APIUnitsSpeed", APIUnitsSpeed);
	Nan::SetPrototypeMethod(tpl, "GetCompoundFeatureCount", GetCompoundFeatureCount);
	Nan::SetPrototypeMethod(tpl, "GetExecutableDistance", GetExecutableDistance);
	Nan::SetPrototypeMethod(tpl, "GetExecutableDistanceUnit", GetExecutableDistanceUnit);
	Nan::SetPrototypeMethod(tpl, "GetExecutableName", GetExecutableName);
	Nan::SetPrototypeMethod(tpl, "GetExecutableWorkpieceRemoval", GetExecutableWorkpieceRemoval);
	Nan::SetPrototypeMethod(tpl, "GetFaceEdgeCount", GetFaceEdgeCount);
	Nan::SetPrototypeMethod(tpl, "GetFaceEdgeNextPoint", GetFaceEdgeCount);
	Nan::SetPrototypeMethod(tpl, "GetFeatureID", GetFeatureID);
	Nan::SetPrototypeMethod(tpl, "GetFeatureName", GetFeatureName);
	Nan::SetPrototypeMethod(tpl, "GetFeatureOutsideProfileClosedCircular", GetFeatureOutsideProfileClosedCircular);
	Nan::SetPrototypeMethod(tpl, "GetMainWorkplan", GetMainWorkplan);
	Nan::SetPrototypeMethod(tpl, "GetProcessFeed", GetProcessFeed);
	Nan::SetPrototypeMethod(tpl, "GetProcessFeedUnit", GetProcessFeedUnit);
	Nan::SetPrototypeMethod(tpl, "GetProjectName", GetProjectName);
	Nan::SetPrototypeMethod(tpl, "IsSelective", IsSelective);
	Nan::SetPrototypeMethod(tpl, "IsWorkingstep", IsWorkingstep);
	Nan::SetPrototypeMethod(tpl, "OpenProject", OpenProject);
	Nan::SetPrototypeMethod(tpl, "SaveAsModules", SaveAsModules);
	Nan::SetPrototypeMethod(tpl, "SaveAsP21", SaveAsP21);
	constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked());
	Nan::Set(target, Nan::New("Finder").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
}

NAN_METHOD(Finder::APIUnitsFeed) {
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (!find) //Throw Exception
	return;
    if (info.Length() != 1) //Function takes one argument
	return;
    if (info[0]->IsUndefined()) //Argument should exist
	return;
    if (!info[0]->IsString()) //Throw Exception
	return;
    char * b;
    size_t len = v8StringToChar(info[0], b);
    if (!find->_find->api_unit_feed(b)) //Throw Exception
	return;
    delete[] b;
}
NAN_METHOD(Finder::APIUnitsInch) {

    Finder * find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) {
	return; // Throw Exception
    }
    if (!(info[0]->IsUndefined())) { // function has 0 arguements
	return; //Throw Exeption
    }
    if (!find->_find->api_unit_inch()) {
	return; //throw error
    }
    return;

}

NAN_METHOD(Finder::APIUnitsMM) {

    Finder * find = Nan::ObjectWrap::Unwrap<Finder>(info.This());

    if (find == 0) {
	return; // Throw Exception
    }
    if (!(info[0]->IsUndefined())) { // function has 0 arguements
	return; //Throw Exeption
    }
    if (!find->_find->api_unit_mm()) {
	return; //throw error
    }
    return;
}

NAN_METHOD(Finder::APIUnitsNative) {

    Finder * find = Nan::ObjectWrap::Unwrap<Finder>(info.This());

    if (find == 0) {
	return; // Throw Exception
    }
    if (!(info[0]->IsUndefined())) { // function has 0 arguements
	return; //Throw Exeption
    }
    if (!find->_find->api_unit_native()) {
	return; //throw error
    }
    return;
}

NAN_METHOD(Finder::APIUnitsSpeed) {
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (!find) //Throw Exception
	return;
    if (info.Length() != 1) //Function takes one argument
	return;
    if (info[0]->IsUndefined()) //Argument should exist
	return;
    if (!info[0]->IsString()) //Throw Exception
	return;
    char * b;
    size_t len = v8StringToChar(info[0], b);
    if (!find->_find->api_unit_speed(b)) //Throw Exception
	return;
    delete[] b;
}



NAN_METHOD(Finder::GetCompoundFeatureCount) {

    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) {
	return; //Throw an exception
    }
    if (info.Length() != 1) { // Needs one argument
	return; // Throw an exception
    }
    if (!info[0]->IsInt32()) { // argument of wrong type
	return; //Throw exception
    }
    int size = 0;
    int feature_id = 0;
    double x;
    double y;
    double z;

    if (!find->_find->first_feature_in_compound(info[0]->Int32Value(), feature_id, size, x, y, z)) {
	return; //throw Error
    }

    info.GetReturnValue().Set(size);
    return;
}

NAN_METHOD(Finder::GetExecutableDistance)
{
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) // Throw exception
	return;

    if (info.Length() != 1) // incorrect number of arguments
	return;

    if (!info[0]->IsNumber()) // invalid argument
	return;

    // get this executable's id
    int64_t exe_id = info[0]->IntegerValue();

    double distance = 0.0;
    double over_time, base_time;

    const char *str1, *str2;

    if (!find->_find->compute_best_feed_time(
	(int)exe_id, distance, base_time, over_time, str1, str2
	))	// cpp error
	return;

    info.GetReturnValue().Set(distance);
    return;
}

NAN_METHOD(Finder::GetExecutableDistanceUnit)
{
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) // Throw exception
	return;

    if (info.Length() != 1) // incorrect number of arguments
	return;

    if (!info[0]->IsNumber()) // invalid argument
	return;

    // get this executable's id
    int64_t exe_id = info[0]->IntegerValue();

    const char *dist_unit = 0;
    double over_time, base_time, distance;
    const char *str2;

    if (!find->_find->compute_best_feed_time(
	(int)exe_id, distance, base_time, over_time, dist_unit, str2
	))
	return;

    info.GetReturnValue().Set(CharTov8String((char*) dist_unit));

    return;
}

NAN_METHOD(Finder::GetExecutableName) {
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) // Throw exception
	return;

    if (info.Length() != 1) // incorrect number of arguments
	return;

    if (!info[0]->IsInt32()) // invalid argument
	return;

    const char * name = 0;
    Nan::Maybe<int32_t> t = Nan::To<int32_t>(info[0]);
    if (!find->_find->executable_name(t.FromJust(), name))
	return;

    info.GetReturnValue().Set(CharTov8String((char *)name));
    return;
}

NAN_METHOD(Finder::GetExecutableWorkpieceRemoval)
{
    Finder* find = Nan::ObjectWrap::Unwrap<Finder>(info.This());
    if (find == 0) // Throw exception
	return;

    if (info.Length() != 1) // incorrect number of arguments
	return;

    if (!info[0]->IsInt32())	// invalid argument
	return;

    Nan::Maybe<int32_t> exe_id = Nan::To<int32_t>(info[0]);

    int wp_id = 0;

    if (!find->_find->executable_removal_workpiece(exe_id.FromJust(), wp_id))    // error in cpp
	return;

    info.GetReturnValue().Set(wp_id);

    return;
{'fraction_non_alphanumeric': 0.15678360757528717, 'fraction_numerical': 0.011487115802545793, 'mean_word_length': 4.340185676392573, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2926750', 'n_tokens_mistral': 5552, 'n_tokens_neox': 5444, 'n_words': 1178}