Skip to content
Pattern.py 3.51 KiB
Newer Older
Fabrice Salvaire's avatar
Fabrice Salvaire committed
####################################################################################################
#
Fabrice Salvaire's avatar
Fabrice Salvaire committed
# Patro - A Python library to make patterns for fashion design
Fabrice Salvaire's avatar
Fabrice Salvaire committed
# Copyright (C) 2017 Fabrice Salvaire
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
####################################################################################################

Fabrice Salvaire's avatar
Fabrice Salvaire committed
"""
"""

Fabrice Salvaire's avatar
Fabrice Salvaire committed
####################################################################################################

import logging

from Patro.Common.Object import ObjectNameMixin
from .Sketch import Sketch
Fabrice Salvaire's avatar
Fabrice Salvaire committed
####################################################################################################

_module_logger = logging.getLogger(__name__)

####################################################################################################

class Pattern:

    """Class to implement the root of a pattern"""

    _logger = _module_logger.getChild('Pattern')

Fabrice Salvaire's avatar
Fabrice Salvaire committed
    ##############################################

Fabrice Salvaire's avatar
Fabrice Salvaire committed
    def __init__(self, measurements, unit):
Fabrice Salvaire's avatar
Fabrice Salvaire committed

        self._measurements = measurements
Fabrice Salvaire's avatar
Fabrice Salvaire committed
        self._unit = unit
Fabrice Salvaire's avatar
Fabrice Salvaire committed

        self._scopes = [] # not a dict so as to don't manage renaming

Fabrice Salvaire's avatar
Fabrice Salvaire committed
    ##############################################

    @property
    def measurements(self):
        return self._measurements

Fabrice Salvaire's avatar
Fabrice Salvaire committed
    @property
    def unit(self):
        return self._unit

    ##############################################

Fabrice Salvaire's avatar
Fabrice Salvaire committed
    @property
    def scopes(self):
        return iter(self._scopes)
Fabrice Salvaire's avatar
Fabrice Salvaire committed

    ##############################################

    def scope_names(self):
        return [scope.name for scope in self._scopes]

    ##############################################

    def add_scope(self, name):
        scope = PatternScope(self, name)
        self._scopes.append(scope)
        return scope
Fabrice Salvaire's avatar
Fabrice Salvaire committed

    ##############################################

    def scope(self, id):

        # Fixem: try ? for slice
        if isinstance(id, int):
            return self._scopes[id]
        else:
            for scope in self._scopes:
                if scope.name == id:
                    return scope
            return None

    ##############################################

    def remove_scope(self, name):
        scope = self.scope(name)
        if scope is not None:
            self._scopes.remove(scope)
####################################################################################################
Fabrice Salvaire's avatar
Fabrice Salvaire committed

class PatternScope(ObjectNameMixin):
Fabrice Salvaire's avatar
Fabrice Salvaire committed

    """Class to implement a pattern scope"""
Fabrice Salvaire's avatar
Fabrice Salvaire committed

    _logger = _module_logger.getChild('Pattern')
Fabrice Salvaire's avatar
Fabrice Salvaire committed

    ##############################################

    def __init__(self, pattern, name):
Fabrice Salvaire's avatar
Fabrice Salvaire committed

        super().__init__(name)
        self._pattern = pattern
        self._sketch = Sketch(self)
Fabrice Salvaire's avatar
Fabrice Salvaire committed

    ##############################################

    @property
    def measurements(self):
        return self._pattern.measurements
    @property
    def unit(self):
        return self._pattern._unit
    @property
    def sketch(self):
        return self._sketch