Skip to content
Snippets Groups Projects
object_gui.py 26.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • Maurice Raybaud's avatar
    Maurice Raybaud committed
    # ##### BEGIN GPL LICENSE BLOCK #####
    #
    #  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.
    #
    # ##### END GPL LICENSE BLOCK #####
    
    # <pep8 compliant>
    """User interface for the POV tools"""
    
    import bpy
    
    from bpy.utils import register_class, unregister_class
    from bpy.types import (
        # Operator,
        Menu,
        Panel,
    )
    
    
    # Example of wrapping every class 'as is'
    from bl_ui import properties_data_modifier
    
    for member in dir(properties_data_modifier):
        subclass = getattr(properties_data_modifier, member)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        try:
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            subclass.COMPAT_ENGINES.add('POVRAY_RENDER')
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        except BaseException as e:
            print(e.__doc__)
            print('An exception occurred: {}'.format(e))
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
    del properties_data_modifier
    
    
    from bl_ui import properties_data_mesh
    
    # These panels are kept
    properties_data_mesh.DATA_PT_custom_props_mesh.COMPAT_ENGINES.add('POVRAY_RENDER')
    properties_data_mesh.DATA_PT_context_mesh.COMPAT_ENGINES.add('POVRAY_RENDER')
    
    ## make some native panels contextual to some object variable
    ## by recreating custom panels inheriting their properties
    
    
    from .scripting_gui import VIEW_MT_POV_import
    
    
    class ModifierButtonsPanel:
        """Use this class to define buttons from the modifier tab of
        properties window."""
    
        bl_space_type = 'PROPERTIES'
        bl_region_type = 'WINDOW'
        bl_context = "modifier"
        # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
    
        @classmethod
        def poll(cls, context):
            mods = context.object.modifiers
            rd = context.scene.render
            return mods and (rd.engine in cls.COMPAT_ENGINES)
    
    
    class ObjectButtonsPanel:
        """Use this class to define buttons from the object tab of
        properties window."""
    
        bl_space_type = 'PROPERTIES'
        bl_region_type = 'WINDOW'
        bl_context = "object"
        # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
    
        @classmethod
        def poll(cls, context):
            obj = context.object
            rd = context.scene.render
            return obj and (rd.engine in cls.COMPAT_ENGINES)
    
    
    class PovDataButtonsPanel(properties_data_mesh.MeshButtonsPanel):
        """Use this class to define buttons from the edit data tab of
        properties window."""
    
        COMPAT_ENGINES = {'POVRAY_RENDER'}
        POV_OBJECT_TYPES = {
            'PLANE',
            'BOX',
            'SPHERE',
            'CYLINDER',
            'CONE',
            'TORUS',
            'BLOB',
            'ISOSURFACE',
            'SUPERELLIPSOID',
            'SUPERTORUS',
            'HEIGHT_FIELD',
            'PARAMETRIC',
            'POLYCIRCLE',
        }
    
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            # We use our parent class poll func too, avoids to re-define too much things...
            return (
                super(PovDataButtonsPanel, cls).poll(context)
                and obj
                and obj.pov.object_as not in cls.POV_OBJECT_TYPES
            )
    
    
    # We cannot inherit from RNA classes (like e.g. properties_data_mesh.DATA_PT_vertex_groups).
    # Complex py/bpy/rna interactions (with metaclass and all) simply do not allow it to work.
    # So we simply have to explicitly copy here the interesting bits. ;)
    class DATA_PT_POV_normals(PovDataButtonsPanel, Panel):
        bl_label = properties_data_mesh.DATA_PT_normals.bl_label
    
        draw = properties_data_mesh.DATA_PT_normals.draw
    
    
    class DATA_PT_POV_texture_space(PovDataButtonsPanel, Panel):
        bl_label = properties_data_mesh.DATA_PT_texture_space.bl_label
        bl_options = properties_data_mesh.DATA_PT_texture_space.bl_options
    
        draw = properties_data_mesh.DATA_PT_texture_space.draw
    
    
    class DATA_PT_POV_vertex_groups(PovDataButtonsPanel, Panel):
        bl_label = properties_data_mesh.DATA_PT_vertex_groups.bl_label
    
        draw = properties_data_mesh.DATA_PT_vertex_groups.draw
    
    
    class DATA_PT_POV_shape_keys(PovDataButtonsPanel, Panel):
        bl_label = properties_data_mesh.DATA_PT_shape_keys.bl_label
    
        draw = properties_data_mesh.DATA_PT_shape_keys.draw
    
    
    class DATA_PT_POV_uv_texture(PovDataButtonsPanel, Panel):
        bl_label = properties_data_mesh.DATA_PT_uv_texture.bl_label
    
        draw = properties_data_mesh.DATA_PT_uv_texture.draw
    
    
    class DATA_PT_POV_vertex_colors(PovDataButtonsPanel, Panel):
        bl_label = properties_data_mesh.DATA_PT_vertex_colors.bl_label
    
        draw = properties_data_mesh.DATA_PT_vertex_colors.draw
    
    
    class DATA_PT_POV_customdata(PovDataButtonsPanel, Panel):
        bl_label = properties_data_mesh.DATA_PT_customdata.bl_label
        bl_options = properties_data_mesh.DATA_PT_customdata.bl_options
        draw = properties_data_mesh.DATA_PT_customdata.draw
    
    
    del properties_data_mesh
    
    
    class MODIFIERS_PT_POV_modifiers(ModifierButtonsPanel, Panel):
        """Use this class to define pov modifier buttons. (For booleans)"""
    
        bl_label = "POV-Ray"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        # def draw_header(self, context):
        # scene = context.scene
        # self.layout.prop(scene.pov, "boolean_mod", text="")
    
        def draw(self, context):
            # scene = context.scene
            layout = self.layout
            ob = context.object
            mod = ob.modifiers
            col = layout.column()
            # Find Boolean Modifiers for displaying CSG option
            onceCSG = 0
            for mod in ob.modifiers:
                if onceCSG == 0:
                    if mod:
                        if mod.type == 'BOOLEAN':
                            col.prop(ob.pov, "boolean_mod")
                            onceCSG = 1
    
                        if ob.pov.boolean_mod == "POV":
                            split = layout.split()
                            col = layout.column()
                            # Inside Vector for CSG
                            col.prop(ob.pov, "inside_vector")
    
    
    class OBJECT_PT_POV_obj_parameters(ObjectButtonsPanel, Panel):
        """Use this class to define pov specific object level options buttons."""
    
        bl_label = "POV"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        @classmethod
        def poll(cls, context):
    
            engine = context.scene.render.engine
            return engine in cls.COMPAT_ENGINES
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            split = layout.split()
    
            col = split.column(align=True)
    
            col.label(text="Radiosity:")
            col.prop(obj.pov, "importance_value", text="Importance")
            col.label(text="Photons:")
            col.prop(obj.pov, "collect_photons", text="Receive Photon Caustics")
            if obj.pov.collect_photons:
                col.prop(obj.pov, "spacing_multiplier", text="Photons Spacing Multiplier")
    
            split = layout.split()
    
            col = split.column()
            col.prop(obj.pov, "hollow")
            col.prop(obj.pov, "double_illuminate")
    
            if obj.type == 'META' or obj.pov.curveshape == 'lathe':
                # if obj.pov.curveshape == 'sor'
                col.prop(obj.pov, "sturm")
            col.prop(obj.pov, "no_shadow")
            col.prop(obj.pov, "no_image")
            col.prop(obj.pov, "no_reflection")
            col.prop(obj.pov, "no_radiosity")
            col.prop(obj.pov, "inverse")
            col.prop(obj.pov, "hierarchy")
            # col.prop(obj.pov,"boundorclip",text="Bound / Clip")
            # if obj.pov.boundorclip != "none":
            # col.prop_search(obj.pov,"boundorclipob",context.blend_data,"objects",text="Object")
            # text = "Clipped by"
            # if obj.pov.boundorclip == "clipped_by":
            # text = "Bounded by"
            # col.prop(obj.pov,"addboundorclip",text=text)
    
    
    class OBJECT_PT_POV_obj_sphere(PovDataButtonsPanel, Panel):
        """Use this class to define pov sphere primitive parameters buttons."""
    
        bl_label = "POV Sphere"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
        # bl_options = {'HIDE_HEADER'}
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return obj and obj.pov.object_as == 'SPHERE' and (engine in cls.COMPAT_ENGINES)
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            col = layout.column()
    
            if obj.pov.object_as == 'SPHERE':
                if not obj.pov.unlock_parameters:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Exported parameters below", icon='LOCKED'
                    )
                    col.label(text="Sphere radius: " + str(obj.pov.sphere_radius))
    
                else:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Edit exported parameters", icon='UNLOCKED'
                    )
                    col.label(text="3D view proxy may get out of synch")
                    col.active = obj.pov.unlock_parameters
    
                    layout.operator("pov.sphere_update", text="Update", icon="SHADING_RENDERED")
    
                    # col.label(text="Parameters:")
                    col.prop(obj.pov, "sphere_radius", text="Radius of Sphere")
    
    
    class OBJECT_PT_POV_obj_cylinder(PovDataButtonsPanel, Panel):
        """Use this class to define pov cylinder primitive parameters buttons."""
    
        bl_label = "POV Cylinder"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
        # bl_options = {'HIDE_HEADER'}
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return obj and obj.pov.object_as == 'CYLINDER' and (engine in cls.COMPAT_ENGINES)
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            col = layout.column()
    
            if obj.pov.object_as == 'CYLINDER':
                if not obj.pov.unlock_parameters:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Exported parameters below", icon='LOCKED'
                    )
                    col.label(text="Cylinder radius: " + str(obj.pov.cylinder_radius))
                    col.label(text="Cylinder cap location: " + str(obj.pov.cylinder_location_cap))
    
                else:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Edit exported parameters", icon='UNLOCKED'
                    )
                    col.label(text="3D view proxy may get out of synch")
                    col.active = obj.pov.unlock_parameters
    
                    layout.operator("pov.cylinder_update", text="Update", icon="MESH_CYLINDER")
    
                    # col.label(text="Parameters:")
                    col.prop(obj.pov, "cylinder_radius")
                    col.prop(obj.pov, "cylinder_location_cap")
    
    
    class OBJECT_PT_POV_obj_cone(PovDataButtonsPanel, Panel):
        """Use this class to define pov cone primitive parameters buttons."""
    
        bl_label = "POV Cone"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
        # bl_options = {'HIDE_HEADER'}
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return obj and obj.pov.object_as == 'CONE' and (engine in cls.COMPAT_ENGINES)
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            col = layout.column()
    
            if obj.pov.object_as == 'CONE':
                if not obj.pov.unlock_parameters:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Exported parameters below", icon='LOCKED'
                    )
                    col.label(text="Cone base radius: " + str(obj.pov.cone_base_radius))
                    col.label(text="Cone cap radius: " + str(obj.pov.cone_cap_radius))
                    col.label(text="Cone proxy segments: " + str(obj.pov.cone_segments))
                    col.label(text="Cone height: " + str(obj.pov.cone_height))
                else:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Edit exported parameters", icon='UNLOCKED'
                    )
                    col.label(text="3D view proxy may get out of synch")
                    col.active = obj.pov.unlock_parameters
    
                    layout.operator("pov.cone_update", text="Update", icon="MESH_CONE")
    
                    # col.label(text="Parameters:")
                    col.prop(obj.pov, "cone_base_radius", text="Radius of Cone Base")
                    col.prop(obj.pov, "cone_cap_radius", text="Radius of Cone Cap")
                    col.prop(obj.pov, "cone_segments", text="Segmentation of Cone proxy")
                    col.prop(obj.pov, "cone_height", text="Height of the cone")
    
    
    class OBJECT_PT_POV_obj_superellipsoid(PovDataButtonsPanel, Panel):
        """Use this class to define pov superellipsoid primitive parameters buttons."""
    
        bl_label = "POV Superquadric ellipsoid"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
        # bl_options = {'HIDE_HEADER'}
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return obj and obj.pov.object_as == 'SUPERELLIPSOID' and (engine in cls.COMPAT_ENGINES)
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            col = layout.column()
    
            if obj.pov.object_as == 'SUPERELLIPSOID':
                if not obj.pov.unlock_parameters:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Exported parameters below", icon='LOCKED'
                    )
                    col.label(text="Radial segmentation: " + str(obj.pov.se_u))
                    col.label(text="Lateral segmentation: " + str(obj.pov.se_v))
                    col.label(text="Ring shape: " + str(obj.pov.se_n1))
                    col.label(text="Cross-section shape: " + str(obj.pov.se_n2))
                    col.label(text="Fill up and down: " + str(obj.pov.se_edit))
                else:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Edit exported parameters", icon='UNLOCKED'
                    )
                    col.label(text="3D view proxy may get out of synch")
                    col.active = obj.pov.unlock_parameters
    
                    layout.operator("pov.superellipsoid_update", text="Update", icon="MOD_SUBSURF")
    
                    # col.label(text="Parameters:")
                    col.prop(obj.pov, "se_u")
                    col.prop(obj.pov, "se_v")
                    col.prop(obj.pov, "se_n1")
                    col.prop(obj.pov, "se_n2")
                    col.prop(obj.pov, "se_edit")
    
    
    class OBJECT_PT_POV_obj_torus(PovDataButtonsPanel, Panel):
        """Use this class to define pov torus primitive parameters buttons."""
    
        bl_label = "POV Torus"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
        # bl_options = {'HIDE_HEADER'}
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return obj and obj.pov.object_as == 'TORUS' and (engine in cls.COMPAT_ENGINES)
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            col = layout.column()
    
            if obj.pov.object_as == 'TORUS':
                if not obj.pov.unlock_parameters:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Exported parameters below", icon='LOCKED'
                    )
                    col.label(text="Torus major radius: " + str(obj.pov.torus_major_radius))
                    col.label(text="Torus minor radius: " + str(obj.pov.torus_minor_radius))
                    col.label(text="Torus major segments: " + str(obj.pov.torus_major_segments))
                    col.label(text="Torus minor segments: " + str(obj.pov.torus_minor_segments))
                else:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Edit exported parameters", icon='UNLOCKED'
                    )
                    col.label(text="3D view proxy may get out of synch")
                    col.active = obj.pov.unlock_parameters
    
                    layout.operator("pov.torus_update", text="Update", icon="MESH_TORUS")
    
                    # col.label(text="Parameters:")
                    col.prop(obj.pov, "torus_major_radius")
                    col.prop(obj.pov, "torus_minor_radius")
                    col.prop(obj.pov, "torus_major_segments")
                    col.prop(obj.pov, "torus_minor_segments")
    
    
    class OBJECT_PT_POV_obj_supertorus(PovDataButtonsPanel, Panel):
        """Use this class to define pov supertorus primitive parameters buttons."""
    
        bl_label = "POV SuperTorus"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
        # bl_options = {'HIDE_HEADER'}
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return obj and obj.pov.object_as == 'SUPERTORUS' and (engine in cls.COMPAT_ENGINES)
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            col = layout.column()
    
            if obj.pov.object_as == 'SUPERTORUS':
                if not obj.pov.unlock_parameters:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Exported parameters below", icon='LOCKED'
                    )
                    col.label(text="SuperTorus major radius: " + str(obj.pov.st_major_radius))
                    col.label(text="SuperTorus minor radius: " + str(obj.pov.st_minor_radius))
                    col.label(text="SuperTorus major segments: " + str(obj.pov.st_u))
                    col.label(text="SuperTorus minor segments: " + str(obj.pov.st_v))
    
                    col.label(text="SuperTorus Ring Manipulator: " + str(obj.pov.st_ring))
                    col.label(text="SuperTorus Cross Manipulator: " + str(obj.pov.st_cross))
                    col.label(text="SuperTorus Internal And External radii: " + str(obj.pov.st_ie))
    
                    col.label(text="SuperTorus accuracy: " + str(obj.pov.st_accuracy))
                    col.label(text="SuperTorus max gradient: " + str(obj.pov.st_max_gradient))
    
                else:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Edit exported parameters", icon='UNLOCKED'
                    )
                    col.label(text="3D view proxy may get out of synch")
                    col.active = obj.pov.unlock_parameters
    
                    layout.operator("pov.supertorus_update", text="Update", icon="MESH_TORUS")
    
                    # col.label(text="Parameters:")
                    col.prop(obj.pov, "st_major_radius")
                    col.prop(obj.pov, "st_minor_radius")
                    col.prop(obj.pov, "st_u")
                    col.prop(obj.pov, "st_v")
                    col.prop(obj.pov, "st_ring")
                    col.prop(obj.pov, "st_cross")
                    col.prop(obj.pov, "st_ie")
                    # col.prop(obj.pov, "st_edit") #?
                    col.prop(obj.pov, "st_accuracy")
                    col.prop(obj.pov, "st_max_gradient")
    
    
    class OBJECT_PT_POV_obj_parametric(PovDataButtonsPanel, Panel):
        """Use this class to define pov parametric surface primitive parameters buttons."""
    
        bl_label = "POV Parametric surface"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
        # bl_options = {'HIDE_HEADER'}
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            obj = context.object
            return obj and obj.pov.object_as == 'PARAMETRIC' and (engine in cls.COMPAT_ENGINES)
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            col = layout.column()
    
            if obj.pov.object_as == 'PARAMETRIC':
                if not obj.pov.unlock_parameters:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Exported parameters below", icon='LOCKED'
                    )
                    col.label(text="Minimum U: " + str(obj.pov.u_min))
                    col.label(text="Minimum V: " + str(obj.pov.v_min))
                    col.label(text="Maximum U: " + str(obj.pov.u_max))
                    col.label(text="Minimum V: " + str(obj.pov.v_min))
                    col.label(text="X Function: " + str(obj.pov.x_eq))
                    col.label(text="Y Function: " + str(obj.pov.y_eq))
                    col.label(text="Z Function: " + str(obj.pov.x_eq))
    
                else:
                    col.prop(
                        obj.pov, "unlock_parameters", text="Edit exported parameters", icon='UNLOCKED'
                    )
                    col.label(text="3D view proxy may get out of synch")
                    col.active = obj.pov.unlock_parameters
    
                    layout.operator("pov.parametric_update", text="Update", icon="SCRIPTPLUGINS")
    
                    col.prop(obj.pov, "u_min", text="Minimum U")
                    col.prop(obj.pov, "v_min", text="Minimum V")
                    col.prop(obj.pov, "u_max", text="Maximum U")
                    col.prop(obj.pov, "v_max", text="Minimum V")
                    col.prop(obj.pov, "x_eq", text="X Function")
                    col.prop(obj.pov, "y_eq", text="Y Function")
                    col.prop(obj.pov, "z_eq", text="Z Function")
    
    
    class OBJECT_PT_povray_replacement_text(ObjectButtonsPanel, Panel):
        """Use this class to define pov object replacement field."""
    
        bl_label = "Custom POV Code"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        def draw(self, context):
            layout = self.layout
    
            obj = context.object
    
            col = layout.column()
            col.label(text="Replace properties with:")
            col.prop(obj.pov, "replacement_text", text="")
    
    
    ###############################################################################
    # Add Povray Objects
    ###############################################################################
    def check_add_mesh_extra_objects():
        """Test if Add mesh extra objects addon is activated
    
        This addon is currently used to generate the proxy for POV parametric
        surface which is almost the same priciple as its Math xyz surface
        """
        if "add_mesh_extra_objects" in bpy.context.preferences.addons.keys():
            return True
        return False
    
    
    def menu_func_add(self, context):
        """Append the POV primitives submenu to blender add objects menu"""
        engine = context.scene.render.engine
        if engine == 'POVRAY_RENDER':
            self.layout.menu("VIEW_MT_POV_primitives_add", icon="PLUGIN")
    
    
    class VIEW_MT_POV_primitives_add(Menu):
        """Define the primitives menu with presets"""
    
        bl_idname = "VIEW_MT_POV_primitives_add"
        bl_label = "Povray"
        COMPAT_ENGINES = {'POVRAY_RENDER'}
    
        @classmethod
        def poll(cls, context):
            engine = context.scene.render.engine
            return engine == 'POVRAY_RENDER'
    
        def draw(self, context):
            layout = self.layout
            layout.operator_context = 'INVOKE_REGION_WIN'
            layout.menu(VIEW_MT_POV_Basic_Shapes.bl_idname, text="Primitives", icon="GROUP")
            layout.menu(VIEW_MT_POV_import.bl_idname, text="Import", icon="IMPORT")
    
    
    class VIEW_MT_POV_Basic_Shapes(Menu):
        """Use this class to sort simple primitives menu entries."""
    
        bl_idname = "POVRAY_MT_basic_shape_tools"
        bl_label = "Basic_shapes"
    
        def draw(self, context):
            layout = self.layout
            layout.operator_context = 'INVOKE_REGION_WIN'
            layout.operator("pov.addplane", text="Infinite Plane", icon='MESH_PLANE')
            layout.operator("pov.addbox", text="Box", icon='MESH_CUBE')
            layout.operator("pov.addsphere", text="Sphere", icon='SHADING_RENDERED')
            layout.operator("pov.addcylinder", text="Cylinder", icon="MESH_CYLINDER")
            layout.operator("pov.cone_add", text="Cone", icon="MESH_CONE")
            layout.operator("pov.addtorus", text="Torus", icon='MESH_TORUS')
            layout.separator()
            layout.operator("pov.addrainbow", text="Rainbow", icon="COLOR")
            layout.operator("pov.addlathe", text="Lathe", icon='MOD_SCREW')
            layout.operator("pov.addprism", text="Prism", icon='MOD_SOLIDIFY')
            layout.operator("pov.addsuperellipsoid", text="Superquadric Ellipsoid", icon='MOD_SUBSURF')
            layout.operator("pov.addheightfield", text="Height Field", icon="RNDCURVE")
            layout.operator("pov.addspheresweep", text="Sphere Sweep", icon='FORCE_CURVE')
            layout.separator()
            layout.operator("pov.addblobsphere", text="Blob Sphere", icon='META_DATA')
            layout.separator()
            layout.label(text="Isosurfaces")
            layout.operator("pov.addisosurfacebox", text="Isosurface Box", icon="META_CUBE")
            layout.operator("pov.addisosurfacesphere", text="Isosurface Sphere", icon="META_BALL")
            layout.operator("pov.addsupertorus", text="Supertorus", icon="SURFACE_NTORUS")
            layout.separator()
            layout.label(text="Macro based")
            layout.operator(
                "pov.addpolygontocircle", text="Polygon To Circle Blending", icon="MOD_CAST"
            )
            layout.operator("pov.addloft", text="Loft", icon="SURFACE_NSURFACE")
            layout.separator()
            # Warning if the Add Advanced Objects addon containing
            # Add mesh extra objects is not enabled
            if not check_add_mesh_extra_objects():
                # col = box.column()
                layout.label(text="Please enable Add Mesh: Extra Objects addon", icon="INFO")
                # layout.separator()
                layout.operator(
                    "preferences.addon_show",
                    text="Go to Add Mesh: Extra Objects addon",
                    icon="PREFERENCES",
                ).module = "add_mesh_extra_objects"
    
                # layout.separator()
                return
            layout.operator("pov.addparametric", text="Parametric", icon='SCRIPTPLUGINS')
    
    
    classes = (
        # ObjectButtonsPanel,
        # PovDataButtonsPanel,
        DATA_PT_POV_normals,
        DATA_PT_POV_texture_space,
        DATA_PT_POV_vertex_groups,
        DATA_PT_POV_shape_keys,
        DATA_PT_POV_uv_texture,
        DATA_PT_POV_vertex_colors,
        DATA_PT_POV_customdata,
        MODIFIERS_PT_POV_modifiers,
        OBJECT_PT_POV_obj_parameters,
        OBJECT_PT_POV_obj_sphere,
        OBJECT_PT_POV_obj_cylinder,
        OBJECT_PT_POV_obj_cone,
        OBJECT_PT_POV_obj_superellipsoid,
        OBJECT_PT_POV_obj_torus,
        OBJECT_PT_POV_obj_supertorus,
        OBJECT_PT_POV_obj_parametric,
        OBJECT_PT_povray_replacement_text,
        VIEW_MT_POV_primitives_add,
        VIEW_MT_POV_Basic_Shapes,
    )
    
    
    def register():
        # from bpy.utils import register_class
    
        for cls in classes:
            register_class(cls)
    
        bpy.types.VIEW3D_MT_add.prepend(menu_func_add)
    
        # was used for parametric objects but made the other addon unreachable on
        # unregister for other tools to use created a user action call instead
        # addon_utils.enable("add_mesh_extra_objects", default_set=False, persistent=True)
    
    
    def unregister():
        # addon_utils.disable("add_mesh_extra_objects", default_set=False)
    
        bpy.types.VIEW3D_MT_add.remove(menu_func_add)
    
        for cls in reversed(classes):
            unregister_class(cls)