From b77c057e7d866ebfcd6829714ed2caed8e292aa4 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Thu, 5 Mar 2020 08:48:13 +0100 Subject: [PATCH] Python fixup after code review --- .../cafPdmScripting/cafPdmPythonGenerator.cpp | 29 +++++++++---- .../cafPdmScriptIOMessages.cpp | 42 +++++++++++++------ .../cafPdmScripting/cafPdmScriptIOMessages.h | 42 +++++++++++++------ .../cafInternalPdmXmlFieldCapability.h | 4 ++ .../cafPdmXml/cafPdmXmlFieldHandle.cpp | 4 +- .../cafPdmXml/cafPdmXmlFieldHandle.h | 5 --- 6 files changed, 87 insertions(+), 39 deletions(-) diff --git a/Fwk/AppFwk/cafPdmScripting/cafPdmPythonGenerator.cpp b/Fwk/AppFwk/cafPdmScripting/cafPdmPythonGenerator.cpp index 211c940a64..5a90f98a2d 100644 --- a/Fwk/AppFwk/cafPdmScripting/cafPdmPythonGenerator.cpp +++ b/Fwk/AppFwk/cafPdmScripting/cafPdmPythonGenerator.cpp @@ -206,20 +206,31 @@ QString PdmPythonGenerator::generate(PdmObjectFactory* factory) const QString commentDataType = field->xmlCapability()->isVectorField() ? QString("List of %1").arg(scriptDataType) : scriptDataType; - QString firstItemTag = pdmChildField ? QString("[0]") : QString(""); QString fullComment = QString(" \"\"\"%1\n Returns:\n %2\n \"\"\"") .arg(comment) .arg(commentDataType); - QString fieldCode = QString(" def %1(self):\n%2\n return " - "self.children(\"%3\", %4)%5\n") - .arg(snake_field_name) - .arg(fullComment) - .arg(scriptability->scriptFieldName()) - .arg(scriptDataType) - .arg(firstItemTag); - classMethodsGenerated[field->ownerClass()][snake_field_name] = fieldCode; + if (pdmChildField) + { + QString fieldCode = QString(" def %1(self):\n%2\n return " + "self.children(\"%3\", %4)[0] if len(self.children) > 0 else None\n") + .arg(snake_field_name) + .arg(fullComment) + .arg(scriptability->scriptFieldName()) + .arg(scriptDataType); + classMethodsGenerated[field->ownerClass()][snake_field_name] = fieldCode; + } + else + { + QString fieldCode = QString(" def %1(self):\n%2\n return " + "self.children(\"%3\", %4)\n") + .arg(snake_field_name) + .arg(fullComment) + .arg(scriptability->scriptFieldName()) + .arg(scriptDataType); + classMethodsGenerated[field->ownerClass()][snake_field_name] = fieldCode; + } } } } diff --git a/Fwk/AppFwk/cafPdmScripting/cafPdmScriptIOMessages.cpp b/Fwk/AppFwk/cafPdmScripting/cafPdmScriptIOMessages.cpp index 4a76d9a127..003d4f41e7 100644 --- a/Fwk/AppFwk/cafPdmScripting/cafPdmScriptIOMessages.cpp +++ b/Fwk/AppFwk/cafPdmScripting/cafPdmScriptIOMessages.cpp @@ -1,20 +1,38 @@ -///////////////////////////////////////////////////////////////////////////////// +//################################################################################################## // -// Copyright (C) 2017 Statoil ASA +// Custom Visualization Core library +// Copyright (C) Ceetron Solutions AS // -// ResInsight 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 may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: // -// ResInsight 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. +// 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. // -// See the GNU General Public License at -// for more details. +// 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 <> +// 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 <> +// for more details. +// +//################################################################################################## #include "cafPdmScriptIOMessages.h" #include diff --git a/Fwk/AppFwk/cafPdmScripting/cafPdmScriptIOMessages.h b/Fwk/AppFwk/cafPdmScripting/cafPdmScriptIOMessages.h index 8ba0a27320..6e2be995ad 100644 --- a/Fwk/AppFwk/cafPdmScripting/cafPdmScriptIOMessages.h +++ b/Fwk/AppFwk/cafPdmScripting/cafPdmScriptIOMessages.h @@ -1,20 +1,38 @@ -///////////////////////////////////////////////////////////////////////////////// +//################################################################################################## // -// Copyright (C) 2017 Statoil ASA +// Custom Visualization Core library +// Copyright (C) Ceetron Solutions AS // -// ResInsight 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 may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: // -// ResInsight 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. +// 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. // -// See the GNU General Public License at -// for more details. +// 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 <> +// 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 <> +// for more details. +// +//################################################################################################## #pragma once #include diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldCapability.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldCapability.h index acb1bce005..570f9221d9 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldCapability.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldCapability.h @@ -12,6 +12,10 @@ template < typename FieldType> class PdmFieldXmlCap : public PdmXmlFieldHandle { public: + // Type traits magic to check if a template argument is a vector + template struct is_vector : public std::false_type {}; + template struct is_vector> : public std::true_type {}; + PdmFieldXmlCap(FieldType* field, bool giveOwnership) : PdmXmlFieldHandle(field, giveOwnership) { m_field = field; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXmlFieldHandle.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXmlFieldHandle.cpp index e8c6b951e2..693520d726 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXmlFieldHandle.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXmlFieldHandle.cpp @@ -54,7 +54,9 @@ void PdmXmlFieldHandle::disableIO() //-------------------------------------------------------------------------------------------------- /// Returns the classKeyword of the child class type, if this field is supposed to contain pointers /// to PdmObjectHandle derived objects. -/// Returns typeid(DataType).name() if the field is not containing some PdmObjectHandle type +/// Returns typeid(DataType).name() if the field is not containing some PdmObjectHandle type. +/// Warning: typeid(DataType).name() is compiler implementation specific and thus you should not +/// Compare this with a predefined literal, like "double" or "float". Instead compare with typeid(double).name(). //-------------------------------------------------------------------------------------------------- QString PdmXmlFieldHandle::dataTypeName() const { diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXmlFieldHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXmlFieldHandle.h index a7337c707d..06a31dd32e 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXmlFieldHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafPdmXmlFieldHandle.h @@ -22,11 +22,6 @@ class PdmReferenceHelper; //================================================================================================== class PdmXmlFieldHandle : public PdmFieldCapability { -public: - // Type traits magic to check if a template argument is a vector - template struct is_vector : public std::false_type {}; - template struct is_vector> : public std::true_type {}; - public: PdmXmlFieldHandle(PdmFieldHandle* owner , bool giveOwnership); ~PdmXmlFieldHandle() override { }