[Feature idea] Sketcher Ctrl-C ctrl-V between projects

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
paddle
Veteran
Posts: 1413
Joined: Mon Feb 03, 2020 4:47 pm

Re: [Feature idea] Sketcher Ctrl-C ctrl-V between projects

Post by paddle »

Ok so the trick was to apply the save and restore functions on the PropertyGeometryList and PropertyConstraintList level. This actually simplified my code by an order of magnitude.

Code: Select all

        Base::StringWriter writer;
        Part::PropertyGeometryList geoToCopy;
        std::vector< Part::Geometry* > newVals;

        for (int i = 0; i < listOfGeoId.size(); i++) {
            const Part::Geometry* Geo = this->getGeometry(listOfGeoId[i]);
            Part::Geometry* geoNew = Geo->copy();
            newVals.push_back(geoNew);
        }
        geoToCopy.setValues(std::move(newVals));
        geoToCopy.Save(writer);
Now the copy paste works perfectly, even between sketches or even between computers. You can even copy paste on the forum to share geometries. Cherry on top is that it uses the syntax and code of the file xml. See this below is the result of my ctrl-C :

Code: Select all

<GeometryList count="3">
    <Geometry  type="Part::GeomCircle">
        <GeoExtensions count="1">
            <GeoExtension type="Sketcher::SketchGeometryExtension" internalGeometryType="0" geometryModeFlags="00000000000000000000000000000000" geometryLayer="0"/>
        </GeoExtensions>
        <Circle CenterX="-94.6912" CenterY="17.6837" CenterZ="0" NormalX="0" NormalY="0" NormalZ="1" AngleXU="-0" Radius="7.55394"/>
    </Geometry>
    <Geometry  type="Part::GeomLineSegment">
        <GeoExtensions count="1">
            <GeoExtension type="Sketcher::SketchGeometryExtension" internalGeometryType="0" geometryModeFlags="00000000000000000000000000000000" geometryLayer="0"/>
        </GeoExtensions>
        <LineSegment StartX="-52.3398" StartY="32.4906" StartZ="0" EndX="-97.8044" EndY="-2.98786" EndZ="0"/>
    </Geometry>
    <Geometry  type="Part::GeomCircle">
        <GeoExtensions count="1">
            <GeoExtension type="Sketcher::SketchGeometryExtension" internalGeometryType="0" geometryModeFlags="00000000000000000000000000000000" geometryLayer="0"/>
        </GeoExtensions>
        <Circle CenterX="-70.0938" CenterY="18.6362" CenterZ="0" NormalX="0" NormalY="0" NormalZ="1" AngleXU="-0" Radius="17.0619"/>
    </Geometry>
</GeometryList>
<ConstraintList count="7">
    <Constrain Name="" Type="6" Value="57.6693" First="1" FirstPos="1" Second="1" SecondPos="2" Third="-2000" ThirdPos="0" LabelDistance="8.56602" LabelPosition="-10.5379" IsDriving="1" IsInVirtualSpace="0" IsActive="1" />
    <Constrain Name="" Type="11" Value="7.55394" First="0" FirstPos="0" Second="-2000" SecondPos="0" Third="-2000" ThirdPos="0" LabelDistance="8.8168" LabelPosition="0.286939" IsDriving="1" IsInVirtualSpace="0" IsActive="1" />
    <Constrain Name="" Type="13" Value="0" First="2" FirstPos="3" Second="1" SecondPos="0" Third="-2000" ThirdPos="0" LabelDistance="10" LabelPosition="0" IsDriving="1" IsInVirtualSpace="0" IsActive="1" />
    <Constrain Name="" Type="5" Value="0" First="2" FirstPos="0" Second="0" SecondPos="0" Third="-2000" ThirdPos="0" LabelDistance="10" LabelPosition="0" IsDriving="1" IsInVirtualSpace="0" IsActive="1" />
    <Constrain Name="" Type="7" Value="70.0938" First="2" FirstPos="3" Second="-1" SecondPos="1" Third="-2000" ThirdPos="0" LabelDistance="7.51938" LabelPosition="-15.1256" IsDriving="1" IsInVirtualSpace="0" IsActive="1" />
    <Constrain Name="" Type="8" Value="18.6362" First="-1" FirstPos="1" Second="2" SecondPos="3" Third="-2000" ThirdPos="0" LabelDistance="-19.9213" LabelPosition="-1.79875" IsDriving="1" IsInVirtualSpace="0" IsActive="1" />
    <Constrain Name="" Type="11" Value="17.0619" First="2" FirstPos="0" Second="-2000" SecondPos="0" Third="-2000" ThirdPos="0" LabelDistance="9.47208" LabelPosition="-0.0775251" IsDriving="1" IsInVirtualSpace="0" IsActive="1" />
</ConstraintList>
To try it out :
https://github.com/PaddleStroke/FreeCAD/tree/ctrlCctrlV
For information it's build on top of my constrainContextually branch. It doesn't requires it actually so another branch could made from the commits to be PR to upstream as standalone.
Post Reply